kolos
This commit is contained in:
commit
c5ea88eae4
|
@ -0,0 +1,31 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29324.140
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kolos", "kolos\kolos.vcxproj", "{588FF52B-B9DE-4724-B46C-124816B4074F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{588FF52B-B9DE-4724-B46C-124816B4074F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{588FF52B-B9DE-4724-B46C-124816B4074F}.Debug|x64.Build.0 = Debug|x64
|
||||
{588FF52B-B9DE-4724-B46C-124816B4074F}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{588FF52B-B9DE-4724-B46C-124816B4074F}.Debug|x86.Build.0 = Debug|Win32
|
||||
{588FF52B-B9DE-4724-B46C-124816B4074F}.Release|x64.ActiveCfg = Release|x64
|
||||
{588FF52B-B9DE-4724-B46C-124816B4074F}.Release|x64.Build.0 = Release|x64
|
||||
{588FF52B-B9DE-4724-B46C-124816B4074F}.Release|x86.ActiveCfg = Release|Win32
|
||||
{588FF52B-B9DE-4724-B46C-124816B4074F}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {BA26AC23-79B1-449F-B33B-FA4F16D32DD1}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,88 @@
|
|||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int N = 10;
|
||||
const int MAXX = 20;
|
||||
|
||||
struct BSTNode {
|
||||
int data;
|
||||
BSTNode* left;
|
||||
BSTNode* right;
|
||||
};
|
||||
|
||||
class BST {
|
||||
int matrix[MAXX][MAXX];
|
||||
|
||||
public:
|
||||
BSTNode* root;
|
||||
BST(int *tab) {
|
||||
for (int i = 0; i < MAXX; i++) {
|
||||
for (int j = 0; j < MAXX; j++) {
|
||||
matrix[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < N; i++) {
|
||||
insert(root, tab[i]);
|
||||
}
|
||||
}
|
||||
|
||||
bool insert(BSTNode*& node, int value) { // polaczenia wiersz > kolumna (przodek > potomek)
|
||||
|
||||
if (node == NULL) {
|
||||
node = new BSTNode;
|
||||
node->data = value;
|
||||
node->left = NULL;
|
||||
node->right = NULL;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if (value < node->data) {
|
||||
return insert(node->left, value);
|
||||
}
|
||||
else if (value > node->data) {
|
||||
return insert(node->right, value);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void buildMatrix(BSTNode* node) {
|
||||
if (node == NULL) return;
|
||||
if (node->left != NULL) {
|
||||
matrix[node->data][node->left->data] = 1;
|
||||
buildMatrix(node->left);
|
||||
}
|
||||
if (node->right != NULL) {
|
||||
matrix[node->data][node->right->data] = 2;
|
||||
buildMatrix(node->right);
|
||||
}
|
||||
}
|
||||
|
||||
void displayMatrix() {
|
||||
cout << endl << endl;
|
||||
for (int i = 0; i < MAXX; i++) {
|
||||
for (int j = 0; j < MAXX; j++) {
|
||||
cout << matrix[i][j] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main() {
|
||||
int tab[N]{ 8, 2, 15, 1, 10, 5, 19, 18, 3, 5 };
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
cout << tab[i] << " ";
|
||||
}
|
||||
|
||||
BST drzewo(tab);
|
||||
|
||||
drzewo.buildMatrix(drzewo.root);
|
||||
|
||||
drzewo.displayMatrix();
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
#include <iostream>
|
||||
#include <stack>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int N = 10; // rozmiar tablicy do posortowania
|
||||
const int MINN = 0; // minimalna wartosc (do stosu lewego)
|
||||
const int MAXX = 100; // maksymalna wartosc (do stosu prawego)
|
||||
|
||||
void displayStack(stack<int> a, string name) {
|
||||
cout << "=====" << name << "=====" << a.size() << endl;
|
||||
while (!a.empty()) {
|
||||
int tmp = a.top();
|
||||
if (tmp < 10) cout << "|" << tmp << " |\n";
|
||||
else cout << "|" << tmp << "|\n";
|
||||
a.pop();
|
||||
}
|
||||
cout << "+--+" << endl;
|
||||
cout << "=====" << name << "=====\n";
|
||||
}
|
||||
|
||||
int amain()
|
||||
{
|
||||
stack<int> stosL, stosP;
|
||||
|
||||
//int memCount[]{ 0, 0, 0 }; // do obliczania zlozonosci
|
||||
|
||||
stosL.push(MINN);
|
||||
stosP.push(MAXX);
|
||||
|
||||
int tab[N]/*{ 2, 8, 15, 1, 10, 5, 19, 18, 3, 5 }*/; // do testow z wartosciami
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
tab[i] = (rand() % (MAXX - 1)) + MINN + 1; // zakres [MINN; MAXX]
|
||||
cout << tab[i] << " ";
|
||||
}
|
||||
cout << endl << endl;
|
||||
|
||||
int mini = tab[0];
|
||||
int maxi = tab[0];
|
||||
for (int a : tab) { // wykonuje sie N razy
|
||||
if (a < mini) mini = a;
|
||||
if (a > maxi) maxi = a;
|
||||
}
|
||||
|
||||
for (int v : tab) { // wykonuje sie N razy
|
||||
while (stosL.top() >= v) {
|
||||
stosP.push(stosL.top());
|
||||
//cout << "L > " << stosL.top() << " > P\n"; // do analizy
|
||||
stosL.pop();
|
||||
//memCount[0]++;
|
||||
}
|
||||
|
||||
while (stosP.top() <= v) {
|
||||
stosL.push(stosP.top());
|
||||
//cout << "P > " << stosP.top() << " > L\n"; // do analizy
|
||||
stosP.pop();
|
||||
//memCount[1]++;
|
||||
}
|
||||
|
||||
stosL.push(v);
|
||||
}
|
||||
|
||||
/*displayStack(stosL, "lewy");
|
||||
displayStack(stosP, "prawy");*/
|
||||
|
||||
while (stosL.empty() == false) {
|
||||
stosP.push(stosL.top());
|
||||
//cout << "L > " << stosL.top() << " > P\n"; // do analizy
|
||||
stosL.pop();
|
||||
//memCount[2]++;
|
||||
}
|
||||
|
||||
/*displayStack(stosL, "lewy");
|
||||
displayStack(stosP, "prawy");*/
|
||||
|
||||
cout << endl;
|
||||
|
||||
while (stosP.empty() == false) { // wykonuje sie N + 2 razy (+2 bo mamy wartosci MINN i MAXX na stosie)
|
||||
int tmp = stosP.top();
|
||||
if (tmp != MAXX && tmp != MINN) cout << tmp << " "; // pomijamy MINN i MAXX bo nie naleza do tab[]
|
||||
stosP.pop();
|
||||
}
|
||||
|
||||
/*cout << endl << "L>P w tablicy: " << memCount[0] <<
|
||||
"\nP>L w tablicy: " << memCount[1] <<
|
||||
"\nL>P pod koniec: " << memCount[2];*/
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<ProjectGuid>{588FF52B-B9DE-4724-B46C-124816B4074F}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>kolos</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="bst.cpp" />
|
||||
<ClCompile Include="kolos.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="kolos.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bst.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
Loading…
Reference in New Issue