diff --git "a/Homework \342\204\2268/AVLTree/AVLTree.sln" "b/Homework \342\204\2268/AVLTree/AVLTree.sln" new file mode 100644 index 0000000..718b45e --- /dev/null +++ "b/Homework \342\204\2268/AVLTree/AVLTree.sln" @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31410.357 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AVLTree", "AVLTree\AVLTree.vcxproj", "{C1059FEC-D8BB-43B7-99BC-52AE57080933}" +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 + {C1059FEC-D8BB-43B7-99BC-52AE57080933}.Debug|x64.ActiveCfg = Debug|x64 + {C1059FEC-D8BB-43B7-99BC-52AE57080933}.Debug|x64.Build.0 = Debug|x64 + {C1059FEC-D8BB-43B7-99BC-52AE57080933}.Debug|x86.ActiveCfg = Debug|Win32 + {C1059FEC-D8BB-43B7-99BC-52AE57080933}.Debug|x86.Build.0 = Debug|Win32 + {C1059FEC-D8BB-43B7-99BC-52AE57080933}.Release|x64.ActiveCfg = Release|x64 + {C1059FEC-D8BB-43B7-99BC-52AE57080933}.Release|x64.Build.0 = Release|x64 + {C1059FEC-D8BB-43B7-99BC-52AE57080933}.Release|x86.ActiveCfg = Release|Win32 + {C1059FEC-D8BB-43B7-99BC-52AE57080933}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A9B119A2-2026-4F5D-A0A8-2558BFF3D344} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2268/AVLTree/AVLTree/AVLTree.c" "b/Homework \342\204\2268/AVLTree/AVLTree/AVLTree.c" new file mode 100644 index 0000000..1eeaec2 --- /dev/null +++ "b/Homework \342\204\2268/AVLTree/AVLTree/AVLTree.c" @@ -0,0 +1,499 @@ +#define _CRT_SECURE_NO_WARNINGS +#include "AVLTree.h" +#include +#include +#include + +typedef struct Node +{ + struct Node* leftSon; + struct Node* rightSon; + struct Node* parent; + char* key; + char* value; + int rightHeight; + int leftHeight; +} Node; + +typedef enum Direction +{ + left, + right +} Direction; + +Node* createTree() +{ + return NULL; +} + +void deleteTreeRecursive(Node* root) +{ + if (root == NULL) + { + return; + } + deleteTreeRecursive(root->leftSon); + deleteTreeRecursive(root->rightSon); + free(root->value); + free(root->key); + free(root); +} + +void deleteTree(Node** root) +{ + deleteTreeRecursive(*root); + *root = NULL; +} + +void attach(Node* parent, Node* child, Direction direction) +{ + if (direction == left) + { + parent->leftSon = child; + } + else + { + parent->rightSon = child; + } + if (child != NULL) + { + child->parent = parent; + } +} + +int maxHeight(Node* x) +{ + if (x == NULL) + { + return -1; + } + return x->leftHeight > x->rightHeight ? x->leftHeight : x->rightHeight; +} + +void checkHeight(Node* x) +{ + while (x->parent != NULL) + { + if (x->parent->leftSon == x) + { + x->parent->leftHeight = maxHeight(x) + 1; + } + else if (x->parent->rightSon == x) + { + x->parent->rightHeight = maxHeight(x) + 1; + } + if (x->parent->rightHeight - x->parent->leftHeight == 2 + || x->parent->rightHeight - x->parent->leftHeight == -2) + { + return; + } + x = x->parent; + } +} + +Node* leftSmallRotation(Node* lastRoot) +{ + Node* newRoot = lastRoot->rightSon; + Node* rootFather = lastRoot->parent; + attach(lastRoot, newRoot->leftSon, right); + attach(newRoot, lastRoot, left); + if (rootFather != NULL) + { + if (rootFather->leftSon == lastRoot) + { + rootFather->leftSon = newRoot; + } + else if (rootFather->rightSon == lastRoot) + { + rootFather->rightSon = newRoot; + } + } + newRoot->parent = rootFather; + lastRoot->rightHeight = maxHeight(lastRoot->rightSon) + 1; + newRoot->leftHeight = maxHeight(lastRoot) + 1; + checkHeight(newRoot); + return newRoot; +} + +Node* rightSmallRotation(Node* lastRoot) +{ + Node* father = lastRoot->parent; + Node* newRoot = lastRoot->leftSon; + attach(lastRoot, newRoot->rightSon, left); + attach(newRoot, lastRoot, right); + if (father != NULL) + { + if (father->leftSon == lastRoot) + { + father->leftSon = newRoot; + } + else if (father->rightSon == lastRoot) + { + father->rightSon = newRoot; + } + } + newRoot->parent = father; + lastRoot->leftHeight = maxHeight(lastRoot->leftSon) + 1; + newRoot->rightHeight = maxHeight(lastRoot) + 1; + checkHeight(newRoot); + return newRoot; +} + +Node* largeLeftRotation(Node* lastRoot) +{ + Node* father = lastRoot->parent; + Node* rightSon = lastRoot->rightSon; + Node* newRoot = rightSon->leftSon; + Node* newLeftSonForRightSon = rightSon->leftSon->rightSon; + Node* newRightSonForLastRoot = rightSon->leftSon->leftSon; + attach(lastRoot, newRightSonForLastRoot, right); + attach(rightSon, newLeftSonForRightSon, left); + attach(newRoot, lastRoot, left); + attach(newRoot, rightSon, right); + if (father != NULL) + { + if (father->leftSon == lastRoot) + { + father->leftSon = newRoot; + } + else if (father->rightSon == lastRoot) + { + father->rightSon = newRoot; + } + } + newRoot->parent = father; + rightSon->leftHeight = maxHeight(newLeftSonForRightSon) + 1; + lastRoot->rightHeight = maxHeight(newRightSonForLastRoot) + 1; + newRoot->leftHeight = maxHeight(lastRoot) + 1; + newRoot->rightHeight = maxHeight(rightSon) + 1; + checkHeight(newRoot); + return newRoot; +} + +Node* largeRightRotation(Node* lastRoot) +{ + Node* father = lastRoot->parent; + Node* leftSon = lastRoot->leftSon; + Node* newRoot = leftSon->rightSon; + Node* newLeftSonForLastRoot = leftSon->rightSon->rightSon; + Node* newRightSonForLeftSon = leftSon->rightSon->leftSon; + attach(lastRoot, newLeftSonForLastRoot, left); + attach(leftSon, newRightSonForLeftSon, right); + attach(newRoot, lastRoot, right); + attach(newRoot, leftSon, left); + if (father != NULL) + { + if (father->leftSon == lastRoot) + { + father->leftSon = newRoot; + } + else if (father->rightSon == lastRoot) + { + father->rightSon = newRoot; + } + } + newRoot->parent = father; + leftSon->rightHeight = maxHeight(newRightSonForLeftSon) + 1; + lastRoot->leftHeight = maxHeight(newLeftSonForLastRoot) + 1; + newRoot->leftHeight = maxHeight(leftSon) + 1; + newRoot->rightHeight = maxHeight(lastRoot) + 1; + checkHeight(newRoot); + return newRoot; +} + +Node* checkBalance(Node* root) +{ + while (root->parent != NULL) + { + if (root->parent->rightHeight - root->parent->leftHeight == -2) + { + if (root->leftHeight >= root->rightHeight) + { + root = rightSmallRotation(root->parent); + } + else + { + root = largeRightRotation(root->parent); + } + } + else if (root->parent->rightHeight - root->parent->leftHeight == 2) + { + if (root->rightHeight >= root->leftHeight) + { + root = leftSmallRotation(root->parent); + } + else + { + root = largeLeftRotation(root->parent); + } + } + if (root->parent == NULL) + { + break; + } + root = root->parent; + } + return root; +} + +Node* createNewNode(Node* root, char* key, char* value, int* error) +{ + char* copyValue = calloc(strlen(value) + 1, sizeof(char)); + if (copyValue == NULL) + { + *error = 1; + return root; + } + strcpy(copyValue, value); + if (root != NULL && key == root->key) + { + free(root->value); + root->value = copyValue; + return root; + } + Node* newNode = (Node*)calloc(1, sizeof(Node)); + if (newNode == NULL) + { + *error = 1; + free(copyValue); + return root; + } + char* keyCopy = calloc(strlen(key) + 1, sizeof(char)); + if (keyCopy == NULL) + { + free(newNode); + free(copyValue); + return root; + } + strcpy(keyCopy, key); + newNode->key = keyCopy; + newNode->value = copyValue; + return newNode; +} + +void startCheckingHeights(Node* root, Node* newRoot, Direction direction) +{ + direction == left ? root->leftHeight++ : root->rightHeight++; + checkHeight(newRoot); +} + +Node* addNode(Node* root, char* key, char* value, int* error) +{ + if (*error != 0) + { + return root; + } + if (root == NULL) + { + return createNewNode(root, key, value, error); + } + while (root != NULL) + { + if (strcmp(key, root->key) > 0) + { + if (root->rightSon == NULL) + { + Node* newRoot = createNewNode(root, key, value, error); + if (*error == 1) + { + return root; + } + attach(root, newRoot, right); + startCheckingHeights(root, newRoot, right); + return checkBalance(newRoot); + } + root = root->rightSon; + } + else if (strcmp(key, root->key) < 0) + { + if (root->leftSon == NULL) + { + Node* newRoot = createNewNode(root, key, value, error); + if (*error == 1) + { + return root; + } + attach(root, newRoot, left); + startCheckingHeights(root, newRoot, left); + return checkBalance(newRoot); + } + root = root->leftSon; + } + else + { + return createNewNode(root, key, value, error); + if (*error == 1) + { + return root; + } + } + } + return root; +} + +Node* search(Node* root, char* key) +{ + Node* node = root; + while (node != NULL) + { + if (strcmp(key, node->key) > 0) + { + node = node->rightSon; + } + else if (strcmp(key, node->key) < 0) + { + node = node->leftSon; + } + else + { + return node; + } + } + return NULL; +} + +void deleteNode(Node** root, char* key, int* error) +{ + if (*error != 0) + { + return; + } + Node* searchResult = search(*root, key); + if (searchResult == NULL) + { + return; + } + *root = searchResult; + if ((*root)->rightSon == NULL && (*root)->leftSon == NULL) + { + Node* parent = (*root)->parent; + if (parent != NULL) + { + if ((*root)->parent->rightSon == *root) + { + (*root)->parent->rightSon = NULL; + parent->rightHeight = 0; + } + else + { + (*root)->parent->leftSon = NULL; + parent->leftHeight = 0; + } + checkHeight(parent); + } + Node* newRoot = checkBalance(*root); + free((*root)->key); + free((*root)->value); + free(*root); + *root = parent == NULL ? NULL : newRoot; + return; + } + if ((*root)->rightSon != NULL && (*root)->leftSon != NULL) + { + Node* currentRoot = *root; + currentRoot = currentRoot->leftSon; + while (currentRoot->rightSon != NULL) + { + currentRoot = currentRoot->rightSon; + } + if (currentRoot == (*root)->leftSon) + { + Node* parent = (*root)->parent; + attach(currentRoot, (*root)->rightSon, right); + if (parent == NULL) + { + currentRoot->parent = NULL; + } + else + { + parent->rightSon == (*root) ? attach((*root)->parent, currentRoot, right) : attach((*root)->parent, currentRoot, left); + } + currentRoot->rightHeight = (*root)->rightHeight; + free((*root)->key); + free((*root)->value); + free(*root); + checkHeight(currentRoot); + *root = checkBalance(currentRoot->rightSon); + return; + } + Node* currentRootParent = currentRoot->parent; + char* newValue = calloc(strlen((currentRoot)->value) + 1, sizeof(char)); + if (newValue == NULL) + { + return; + } + char* newKey = calloc(strlen((currentRoot)->key) + 1, sizeof(char)); + if (newKey == NULL) + { + free(newValue); + return; + } + strcpy(newKey, key); + free((*root)->key); + (*root)->key = newKey; + free((*root)->value); + strcpy(newValue, currentRoot->value); + (*root)->value = newValue; + currentRootParent->rightSon = NULL; + currentRootParent->rightHeight = 0; + checkHeight(currentRootParent); + Node* newRoot = checkBalance(currentRoot); + free(currentRoot->value); + free(currentRoot->key); + free(currentRoot); + *root = newRoot; + return; + } + if ((*root)->parent == NULL) + { + *root = (*root)->rightSon == NULL ? (*root)->leftSon : (*root)->rightSon; + if ((*root)->parent != NULL) + { + free((*root)->parent->value); + free((*root)->parent->key); + } + free((*root)->parent); + (*root)->parent = NULL; + return; + } + Node* parent = (*root)->parent; + Node* newRoot = NULL; + if ((*root)->rightSon == NULL) + { + parent->leftSon == *root ? attach(parent, (*root)->leftSon, left) + : attach(parent, (*root)->leftSon, right); + checkHeight((*root)->leftSon); + newRoot = checkBalance((*root)->leftSon); + } + else + { + parent->leftSon == *root ? attach(parent, (*root)->rightSon, left) + : attach(parent, (*root)->rightSon, right); + checkHeight((*root)->rightSon); + newRoot = checkBalance((*root)->rightSon); + } + free((*root)->value); + free((*root)->key); + free(*root); + *root = newRoot; +} + +bool inTree(Node* root, char* key) +{ + return search(root, key) != NULL; +} + +char* getValue(Node* root, char* key) +{ + Node* searchResult = search(root, key); + if (searchResult == NULL) + { + return NULL; + } + return searchResult->value; +} + +bool invariant(Node* node) +{ + return abs(node->rightHeight - node->leftHeight) < 2; +} \ No newline at end of file diff --git "a/Homework \342\204\2268/AVLTree/AVLTree/AVLTree.h" "b/Homework \342\204\2268/AVLTree/AVLTree/AVLTree.h" new file mode 100644 index 0000000..a48ef54 --- /dev/null +++ "b/Homework \342\204\2268/AVLTree/AVLTree/AVLTree.h" @@ -0,0 +1,26 @@ +#pragma once +#include + +// the structure representing the AVL tree +typedef struct Node Node; + +// function for adding a node to a tree +Node* addNode(Node* root, char* key, char* value, int* error); + +// function for removing a node from a tree +void deleteNode(Node** root, char* key, int* error); + +// function for deleting a tree +void deleteTree(Node** root); + +// function for creating a tree +Node* createTree(); + +// function for getting tree values +char* getValue(Node* root, char* key); + +// function for checking the invariant of the tree +bool invariant(Node* node); + +// function for checking the presence of a key +bool inTree(Node* root, char* key); \ No newline at end of file diff --git "a/Homework \342\204\2268/AVLTree/AVLTree/AVLTree.vcxproj" "b/Homework \342\204\2268/AVLTree/AVLTree/AVLTree.vcxproj" new file mode 100644 index 0000000..2fc10f5 --- /dev/null +++ "b/Homework \342\204\2268/AVLTree/AVLTree/AVLTree.vcxproj" @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {c1059fec-d8bb-43b7-99bc-52ae57080933} + AVLTree + 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;_CRT_SECURE_NO_WARNINGS;_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/Homework \342\204\2268/AVLTree/AVLTree/AVLTree.vcxproj.filters" "b/Homework \342\204\2268/AVLTree/AVLTree/AVLTree.vcxproj.filters" new file mode 100644 index 0000000..f5c5eff --- /dev/null +++ "b/Homework \342\204\2268/AVLTree/AVLTree/AVLTree.vcxproj.filters" @@ -0,0 +1,36 @@ + + + + + {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 + + + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + + + Файлы заголовков + + + Файлы заголовков + + + \ No newline at end of file diff --git "a/Homework \342\204\2268/AVLTree/AVLTree/AVLTreeTest.c" "b/Homework \342\204\2268/AVLTree/AVLTree/AVLTreeTest.c" new file mode 100644 index 0000000..427de22 --- /dev/null +++ "b/Homework \342\204\2268/AVLTree/AVLTree/AVLTreeTest.c" @@ -0,0 +1,82 @@ +#include "AVLTree.h" +#include "AVLTreeTest.h" + +bool addNodeTest() +{ + Node* tree = createTree(); + int error = 0; + tree = addNode(tree, "firstString", "firstString", &error); + tree = addNode(tree, "secondString", "secondString", &error); + bool firstResult = invariant(tree); + tree = addNode(tree, "value", "value", &error); + bool secondResult = invariant(tree); + tree = addNode(tree, "hello world", "hello world", &error); + bool thirdResult = invariant(tree); + tree = addNode(tree, "4 points", "4 points", &error); + bool fourthResult = invariant(tree); + tree = addNode(tree, "AVLTree", "AVLTree", &error); + bool fifthResult = invariant(tree); + tree = addNode(tree, "addNode", "addNode", &error); + bool sixthResult = invariant(tree); + tree = addNode(tree, "i want a session", "i want a session", &error); + bool seventhResult = invariant(tree); + tree = addNode(tree, "twenty", "twenty", &error); + bool eighthResult = invariant(tree); + tree = addNode(tree, "lastValue", "lastValue", &error); + bool ninthResult = invariant(tree); + deleteTree(&tree); + return firstResult && secondResult && thirdResult && fourthResult && fifthResult + && sixthResult && seventhResult && eighthResult && ninthResult; +} + +bool firstDeleteNodeTest() +{ + Node* tree = createTree(); + int error = 0; + tree = addNode(tree, "firstValue", "firstValue", &error); + tree = addNode(tree, "assdf", "assdf", &error); + tree = addNode(tree, "xzcv", "xzcv", &error); + tree = addNode(tree, "htrhrth", "htrhrth", &error); + tree = addNode(tree, "wertyy", "wertyy", &error); + tree = addNode(tree, "fghgf", "fghgf", &error); + tree = addNode(tree, "asfasf", "asfasf", &error); + tree = addNode(tree, "qwrrwq", "qwrrwq", &error); + deleteNode(&tree, "asfasf", &error); + deleteNode(&tree, "htrhrth", &error); + bool firstResult = invariant(tree); + deleteNode(&tree, "assdf", &error); + bool secondResult = invariant(tree); + deleteNode(&tree, "wertyy", &error); + bool thirdResult = invariant(tree); + deleteNode(&tree, "fghgf", &error); + bool fourthResult = invariant(tree); + deleteTree(&tree); + return firstResult && secondResult && thirdResult && fourthResult && error == 0; +} + +bool secondDeleteNodeTest() +{ + Node* tree = createTree(); + int error = 0; + tree = addNode(tree, "frt", "frt", &error); + tree = addNode(tree, "luej", "luej", &error); + tree = addNode(tree, " ", " ", &error); + tree = addNode(tree, "(adsdsd)", "(adsdsd)", &error); + tree = addNode(tree, "firstValue", "firstValue", &error); + tree = addNode(tree, "fcv", "fcv", &error); + tree = addNode(tree, "fi", "fi", &error); + tree = addNode(tree, "kek", "kek", &error); + deleteNode(&tree, "kek", &error); + bool firstResult = invariant(tree); + deleteNode(&tree, "luej", &error); + deleteNode(&tree, "fcv", &error); + bool secondResult = invariant(tree); + deleteNode(&tree, "xzczxc", &error); + bool thirdResult = invariant(tree); + deleteTree(&tree); + return firstResult && secondResult && thirdResult && error == 0; +} +bool allTestResult() +{ + return addNodeTest() && firstDeleteNodeTest() && secondDeleteNodeTest(); +} \ No newline at end of file diff --git "a/Homework \342\204\2268/AVLTree/AVLTree/AVLTreeTest.h" "b/Homework \342\204\2268/AVLTree/AVLTree/AVLTreeTest.h" new file mode 100644 index 0000000..911dcf1 --- /dev/null +++ "b/Homework \342\204\2268/AVLTree/AVLTree/AVLTreeTest.h" @@ -0,0 +1,5 @@ +#pragma once +#include + +// Function for returning test results +bool allTestResult(); \ No newline at end of file diff --git "a/Homework \342\204\2268/AVLTree/AVLTree/Main.c" "b/Homework \342\204\2268/AVLTree/AVLTree/Main.c" new file mode 100644 index 0000000..663d362 --- /dev/null +++ "b/Homework \342\204\2268/AVLTree/AVLTree/Main.c" @@ -0,0 +1,10 @@ +#include "AVLTree.h" +#include "AVLTreeTest.h" + +int main() +{ + if (!allTestResult()) + { + return -1; + } +} \ No newline at end of file diff --git "a/Homework \342\204\2268/InteractiveModeForAVLTree/InteractiveModeForAVLTree.sln" "b/Homework \342\204\2268/InteractiveModeForAVLTree/InteractiveModeForAVLTree.sln" new file mode 100644 index 0000000..5195587 --- /dev/null +++ "b/Homework \342\204\2268/InteractiveModeForAVLTree/InteractiveModeForAVLTree.sln" @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31410.357 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InteractiveModeForAVLTree", "InteractiveModeForAVLTree\InteractiveModeForAVLTree.vcxproj", "{C81F3454-6012-4747-8EDD-BECE10840E5F}" +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 + {C81F3454-6012-4747-8EDD-BECE10840E5F}.Debug|x64.ActiveCfg = Debug|x64 + {C81F3454-6012-4747-8EDD-BECE10840E5F}.Debug|x64.Build.0 = Debug|x64 + {C81F3454-6012-4747-8EDD-BECE10840E5F}.Debug|x86.ActiveCfg = Debug|Win32 + {C81F3454-6012-4747-8EDD-BECE10840E5F}.Debug|x86.Build.0 = Debug|Win32 + {C81F3454-6012-4747-8EDD-BECE10840E5F}.Release|x64.ActiveCfg = Release|x64 + {C81F3454-6012-4747-8EDD-BECE10840E5F}.Release|x64.Build.0 = Release|x64 + {C81F3454-6012-4747-8EDD-BECE10840E5F}.Release|x86.ActiveCfg = Release|Win32 + {C81F3454-6012-4747-8EDD-BECE10840E5F}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AD07C14B-BBC3-4FCB-9D79-3E1BC602B70B} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2268/InteractiveModeForAVLTree/InteractiveModeForAVLTree/InteractiveModeForAVLTree.c" "b/Homework \342\204\2268/InteractiveModeForAVLTree/InteractiveModeForAVLTree/InteractiveModeForAVLTree.c" new file mode 100644 index 0000000..68fd280 --- /dev/null +++ "b/Homework \342\204\2268/InteractiveModeForAVLTree/InteractiveModeForAVLTree/InteractiveModeForAVLTree.c" @@ -0,0 +1,125 @@ +#include "../../AVLTree/AVLTree/AVLTree.h" +#include +#include + +int main() +{ + setlocale(LC_ALL, "rus"); + printf("0 \n"); + printf("1 \n"); + printf("2 \n"); + printf("3 \n"); + printf("4 \n"); + Node* tree = createTree(); + int number = 1; + int error = 0; + while (number != 0) + { + printf(" \n"); + while (scanf_s("%d", &number) == 0) + { + printf(" 0 4\n"); + while (getchar() != '\n') + { + continue; + } + } + switch (number) + { + case 0: + { + deleteTree(&tree); + return 0; + } + case 1: + { + printf(" ( 100 )\n"); + char key[100] = {'\0'}; + const int firstScanfResult = scanf_s("%s", key, (unsigned)sizeof(key)); + if (firstScanfResult == 0) + { + printf(" \n"); + break; + } + printf(" ( 100 )\n"); + char string[100] = { '\0' }; + const int secondScanfResult = scanf_s("%s", string, (unsigned)sizeof(string)); + if (secondScanfResult == 0) + { + printf(" \n"); + break; + } + tree = addNode(tree, key, string, &error); + if (error == 1) + { + deleteTree(&tree); + printf(" \n"); + return -1; + } + printf(" \n"); + break; + } + case 2: + { + printf(" ( 100 )\n"); + char key[100] = { '\0' }; + const int firstScanfResult = scanf_s("%s", key, (unsigned)sizeof(key)); + if (firstScanfResult == 0) + { + printf(" \n"); + break; + } + printf("%s\n", getValue(tree, key)); + break; + } + case 3: + { + printf(" ( 100 )\n"); + char key[100] = { '\0' }; + const int firstScanfResult = scanf_s("%s", key, (unsigned)sizeof(key)); + if (firstScanfResult == 0) + { + printf(" \n"); + break; + } + bool result = inTree(tree, key); + if (!result) + { + printf(" \n"); + break; + } + printf(" \n"); + break; + } + case 4: + { + printf(" ( 100 )\n"); + char key[100] = { '\0' }; + const int firstScanfResult = scanf_s("%s", key, (unsigned)sizeof(key)); + if (firstScanfResult == 0) + { + printf(" \n"); + break; + } + deleteNode(&tree, key, &error); + if (error == 1) + { + printf(" \n"); + return -1; + } + if (error == 2) + { + printf(" \n"); + break; + } + printf(" \n"); + break; + } + default: + { + printf(" 0 4\n"); + break; + } + } + } +} \ No newline at end of file diff --git "a/Homework \342\204\2268/InteractiveModeForAVLTree/InteractiveModeForAVLTree/InteractiveModeForAVLTree.vcxproj" "b/Homework \342\204\2268/InteractiveModeForAVLTree/InteractiveModeForAVLTree/InteractiveModeForAVLTree.vcxproj" new file mode 100644 index 0000000..26749da --- /dev/null +++ "b/Homework \342\204\2268/InteractiveModeForAVLTree/InteractiveModeForAVLTree/InteractiveModeForAVLTree.vcxproj" @@ -0,0 +1,151 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {c81f3454-6012-4747-8edd-bece10840e5f} + InteractiveModeForAVLTree + 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;_CRT_SECURE_NO_WARNINGS;_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/Homework \342\204\2268/InteractiveModeForAVLTree/InteractiveModeForAVLTree/InteractiveModeForAVLTree.vcxproj.filters" "b/Homework \342\204\2268/InteractiveModeForAVLTree/InteractiveModeForAVLTree/InteractiveModeForAVLTree.vcxproj.filters" new file mode 100644 index 0000000..c1a5e51 --- /dev/null +++ "b/Homework \342\204\2268/InteractiveModeForAVLTree/InteractiveModeForAVLTree/InteractiveModeForAVLTree.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 + + + + + Исходные файлы + + + Исходные файлы + + + + + Файлы заголовков + + + \ No newline at end of file