commit 2cf9d4a4271cd7ef9b3aac4344a89591981b781c Author: MikoÅ‚aj Rosa Date: Mon May 30 15:28:29 2022 +0200 Initial commit diff --git a/desktop.ini b/desktop.ini new file mode 100644 index 0000000..0a96cae Binary files /dev/null and b/desktop.ini differ diff --git a/drzewa binarne BST.pdf b/drzewa binarne BST.pdf new file mode 100644 index 0000000..f56c988 Binary files /dev/null and b/drzewa binarne BST.pdf differ diff --git a/pliki_do_zadan_BST/BST/BST.sln b/pliki_do_zadan_BST/BST/BST.sln new file mode 100644 index 0000000..ad9ca74 --- /dev/null +++ b/pliki_do_zadan_BST/BST/BST.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31105.61 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BST", "BST\BST.vcxproj", "{BE026CE1-51B4-49E7-82A7-B84B9849E3A2}" +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 + {BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Debug|x64.ActiveCfg = Debug|x64 + {BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Debug|x64.Build.0 = Debug|x64 + {BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Debug|x86.ActiveCfg = Debug|Win32 + {BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Debug|x86.Build.0 = Debug|Win32 + {BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Release|x64.ActiveCfg = Release|x64 + {BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Release|x64.Build.0 = Release|x64 + {BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Release|x86.ActiveCfg = Release|Win32 + {BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E9400436-F9FC-425A-98F3-10BFDFEDECE1} + EndGlobalSection +EndGlobal diff --git a/pliki_do_zadan_BST/BST/BST/BST.cpp b/pliki_do_zadan_BST/BST/BST/BST.cpp new file mode 100644 index 0000000..3f759fd --- /dev/null +++ b/pliki_do_zadan_BST/BST/BST/BST.cpp @@ -0,0 +1,67 @@ +#include +#include "BST.h" +using namespace std; + +BST::BST():root(NULL) {} + +BST::BST(int tab[], int size) { + for (int i = 0; i < size; i++) + insert(root, tab[i]); +} + +bool BST::insert(BSTNode*& node, int wartosc) { + if (node == NULL) { // tworzymy i doÅ‚Ä…czamy wÄ™zeÅ‚ + node = new BSTNode; + node->data = wartosc; + node->left = NULL; + node->right = NULL; + return true; + } + else + if (wartosc < node->data) return insert(node->left, wartosc); // rekurencyjne wywolanie + else + if (wartosc > node->data) return insert(node->right, wartosc); // rekurencyjne wywolanie + // uwaga: liczby powtarzajÄ…ce siÄ™ nie sÄ… dodawane do drzewa + + return false; +} + +//BSTNode* BST::search(int key) {} + +//BSTNode* BST::search(BSTNode* node, int key) {} + +//int BST::minKey() {} + +//int BST::minKey(BSTNode* node) {} + +//int BST::maxKey() {} + +//void BST::inorder(BSTNode* x) {} + +//void BST::preorder(BSTNode* x) {} + +//void BST::postorder(BSTNode* x) {} + +void BST::print(BSTNode* x){ + if (!x->left && !x->right) return; + + cout << x->data << " : lewy-> "; + if (x->left) cout << x->left->data; + else cout << "NULL"; + + cout << ", prawy-> "; + if (x->right) cout << x->right->data; + else cout << "NULL"; + cout << endl; + + if (x->left) print(x->left); + if (x->right) print(x->right); +} + +void BST::remove(BSTNode* x) { + if (!x) return; + remove(x->left); + remove(x->right); + cout << "usuwam " << x->data << endl; + delete x; +} \ No newline at end of file diff --git a/pliki_do_zadan_BST/BST/BST/BST.h b/pliki_do_zadan_BST/BST/BST/BST.h new file mode 100644 index 0000000..65b7178 --- /dev/null +++ b/pliki_do_zadan_BST/BST/BST/BST.h @@ -0,0 +1,32 @@ +#pragma once +class BSTNode { +public: + int data; + BSTNode* left, * right; +}; + +class BST +{ +public: + BSTNode* root; // korzeñ drzewa + + BST(); + BST(int T[], int size); //tworzy drzewo na podstawie tablicy + ~BST() { remove(root); }; //usuwa drzewo, zwalnia pamiêæ + + bool insert(BSTNode*& node, int wartosc); //zwraca true - wezê³ dodany, false-wêze³ ju¿ jest + void remove(BSTNode* x); //usuwa poddrzewa o korzeniu w x + BSTNode* search(int key); //zwraca wsk. na wêze³ zawieraj¹cy klucz key lub + //NULL, jeœli drzewo BST nie posiada takiego wêz³a. + int maxKey(); + int minKey(); + + BSTNode* search(BSTNode* node, int key); + int minKey(BSTNode*); + void inorder(BSTNode* x); + void preorder(BSTNode* x); + void postorder(BSTNode* x); + + void print(BSTNode* ); + +}; diff --git a/pliki_do_zadan_BST/BST/BST/BST.vcxproj b/pliki_do_zadan_BST/BST/BST/BST.vcxproj new file mode 100644 index 0000000..c9f8d57 --- /dev/null +++ b/pliki_do_zadan_BST/BST/BST/BST.vcxproj @@ -0,0 +1,151 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {be026ce1-51b4-49e7-82a7-b84b9849e3a2} + BST + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/pliki_do_zadan_BST/BST/BST/BST.vcxproj.filters b/pliki_do_zadan_BST/BST/BST/BST.vcxproj.filters new file mode 100644 index 0000000..d56e3f2 --- /dev/null +++ b/pliki_do_zadan_BST/BST/BST/BST.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;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 + + + + + Pliki źródÅ‚owe + + + Pliki źródÅ‚owe + + + + + Pliki nagłówkowe + + + \ No newline at end of file diff --git a/pliki_do_zadan_BST/BST/BST/BST.vcxproj.user b/pliki_do_zadan_BST/BST/BST/BST.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/pliki_do_zadan_BST/BST/BST/BST.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/pliki_do_zadan_BST/BST/BST/main.cpp b/pliki_do_zadan_BST/BST/BST/main.cpp new file mode 100644 index 0000000..122356b --- /dev/null +++ b/pliki_do_zadan_BST/BST/BST/main.cpp @@ -0,0 +1,14 @@ +#include +#include "BST.h" +using namespace std; + +int main() +{ + int dane[]{ 8, 3, 6, 1, 7, 10, 0, 2, 11, 4, 9 }; //{ 10,6,15,1,8,12,16,0,2,7,9 }; + BST drzewo(dane, size(dane)); + drzewo.print(drzewo.root); + + cout << endl; + + return 0; +} diff --git a/pliki_do_zadan_BST/zadania_BST.xlsx b/pliki_do_zadan_BST/zadania_BST.xlsx new file mode 100644 index 0000000..40ac8ad Binary files /dev/null and b/pliki_do_zadan_BST/zadania_BST.xlsx differ