commit c5ea88eae43a38b56fbcca45b8e831b580db74ec Author: Mikołaj Rosa Date: Mon Jun 6 17:15:39 2022 +0200 kolos diff --git a/kolos.sln b/kolos.sln new file mode 100644 index 0000000..6143f93 --- /dev/null +++ b/kolos.sln @@ -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 diff --git a/kolos/bst.cpp b/kolos/bst.cpp new file mode 100644 index 0000000..551e2a8 --- /dev/null +++ b/kolos/bst.cpp @@ -0,0 +1,88 @@ +#include + +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(); +} \ No newline at end of file diff --git a/kolos/kolos.cpp b/kolos/kolos.cpp new file mode 100644 index 0000000..c2449e2 --- /dev/null +++ b/kolos/kolos.cpp @@ -0,0 +1,90 @@ +#include +#include + +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 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 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; +} diff --git a/kolos/kolos.vcxproj b/kolos/kolos.vcxproj new file mode 100644 index 0000000..44c646d --- /dev/null +++ b/kolos/kolos.vcxproj @@ -0,0 +1,160 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {588FF52B-B9DE-4724-B46C-124816B4074F} + Win32Proj + kolos + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + \ No newline at end of file diff --git a/kolos/kolos.vcxproj.filters b/kolos/kolos.vcxproj.filters new file mode 100644 index 0000000..0d74fc8 --- /dev/null +++ b/kolos/kolos.vcxproj.filters @@ -0,0 +1,25 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/kolos/kolos.vcxproj.user b/kolos/kolos.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/kolos/kolos.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file