From c3bb4c124f9a9385b3dd69074694c36a3c19801b Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Wed, 10 Nov 2021 04:58:13 +0500 Subject: [PATCH 1/6] Writing all functions and tests for them --- Tree/Tree.sln | 31 +++ Tree/Tree/Main.c | 10 + Tree/Tree/TestTree.c | 87 +++++++ Tree/Tree/TestTree.h | 14 ++ Tree/Tree/Tree.c | 409 +++++++++++++++++++++++++++++++++ Tree/Tree/Tree.h | 25 ++ Tree/Tree/Tree.vcxproj | 153 ++++++++++++ Tree/Tree/Tree.vcxproj.filters | 36 +++ 8 files changed, 765 insertions(+) create mode 100644 Tree/Tree.sln create mode 100644 Tree/Tree/Main.c create mode 100644 Tree/Tree/TestTree.c create mode 100644 Tree/Tree/TestTree.h create mode 100644 Tree/Tree/Tree.c create mode 100644 Tree/Tree/Tree.h create mode 100644 Tree/Tree/Tree.vcxproj create mode 100644 Tree/Tree/Tree.vcxproj.filters diff --git a/Tree/Tree.sln b/Tree/Tree.sln new file mode 100644 index 0000000..a09c740 --- /dev/null +++ b/Tree/Tree.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}") = "Tree", "Tree\Tree.vcxproj", "{1B08B554-064D-4A2D-A418-3C73FF3D4652}" +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 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Debug|x64.ActiveCfg = Debug|x64 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Debug|x64.Build.0 = Debug|x64 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Debug|x86.ActiveCfg = Debug|Win32 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Debug|x86.Build.0 = Debug|Win32 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Release|x64.ActiveCfg = Release|x64 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Release|x64.Build.0 = Release|x64 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Release|x86.ActiveCfg = Release|Win32 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0EEF711C-36E8-4AC3-9FFA-66083037F612} + EndGlobalSection +EndGlobal diff --git a/Tree/Tree/Main.c b/Tree/Tree/Main.c new file mode 100644 index 0000000..48035ec --- /dev/null +++ b/Tree/Tree/Main.c @@ -0,0 +1,10 @@ +#include "Tree.h" +#include "TestTree.h" + +int main() +{ + if (!testAddNode() || !testDeleteNode() || !testInTree() || !testGetValue()) + { + return -1; + } +} \ No newline at end of file diff --git a/Tree/Tree/TestTree.c b/Tree/Tree/TestTree.c new file mode 100644 index 0000000..1c46b85 --- /dev/null +++ b/Tree/Tree/TestTree.c @@ -0,0 +1,87 @@ +#include "TestTree.h" +#include "Tree.h" +#include + +bool testAddNode() +{ + Node* tree = createTree(); + tree = addNode(tree, 3, "asdadsdsa"); + tree = addNode(tree, 5, "sdadad"); + bool firstCheck = isFather(tree, 5, 3); + tree = addNode(tree, 1, "wdwddw"); + bool secondCheck = isFather(tree, 1, 3); + bool thirdCheck = isFather(tree, 3, 5); + tree = addNode(tree, 6, "afwfwfw"); + bool fourthCheck = isFather(tree, 6, 1); + bool fifthCheck = isFather(tree, 1, 5); + bool sixthCheck = isFather(tree, 5, 3); + tree = addNode(tree, 2, "adwdwd"); + bool seventhCheck = isFather(tree, 2, 1); + bool eighthCheck = isFather(tree, 2, 6); + bool ninthCheck = isFather(tree, 6, 3); + bool tenthCheck = isFather(tree, 3, 5); + deleteTree(&tree); + return firstCheck && secondCheck && thirdCheck + && fourthCheck && fifthCheck && sixthCheck + && seventhCheck && eighthCheck && ninthCheck && tenthCheck; +} + +bool testDeleteNode() +{ + Node* tree = createTree(); + tree = addNode(tree, 3, "Hello World"); + tree = addNode(tree, 8, "Hello army"); + tree = addNode(tree, 1, "AVL tree"); + tree = addNode(tree, -8, "^-^"); + tree = addNode(tree, 12, "Test"); + tree = addNode(tree, 2, "git commit"); + tree = deleteNode(tree, 12); + bool firstCheck = inTree(tree, 12); + tree = deleteNode(tree, 1); + bool secondCheck = inTree(tree, 1); + tree = deleteNode(tree, -8); + bool thirdCheck = inTree(tree, -8); + deleteTree(&tree); + return !firstCheck && !secondCheck && !thirdCheck; +} + +bool testInTree() +{ + Node* tree = createTree(); + tree = addNode(tree, 3, "cyclic list"); + tree = addNode(tree, -123, "Memory link"); + tree = addNode(tree, 10, "git checkout -b"); + tree = addNode(tree, -5, "eeeeee"); + tree = addNode(tree, 12, "stormbringer"); + tree = addNode(tree, 2, "i surrender"); + bool firstCheck = inTree(tree, 3); + bool secondCheck = inTree(tree, -5); + bool thirdCheck = inTree(tree, 12); + bool fourthCheck = inTree(tree, 2); + bool fifthCheck = inTree(tree,-123); + + bool sixthCheck = inTree(tree, 2021); + tree = deleteNode(tree, 2); + bool seventhCheck = inTree(tree, 2); + bool eighthCheck = inTree(tree, 0); + tree = deleteNode(tree, -123); + bool ninthCheck = inTree(tree, -123); + bool tenthCheck = inTree(tree, -47); + deleteTree(&tree); + return firstCheck && secondCheck && thirdCheck + && fourthCheck && fifthCheck && !sixthCheck + && !seventhCheck && !eighthCheck && !ninthCheck && !tenthCheck; +} + +bool testGetValue() +{ + Node* tree = createTree(); + tree = addNode(tree, 3, "cyclic list"); + tree = addNode(tree, 10, "git checkout -b"); + const char* firstValue = getValue(tree, 3); + const char* secondValue = getValue(tree, 4); + const char* thirdValue = getValue(tree, 10); + bool result = strcmp(firstValue, "cyclic list") == 0 && strcmp(thirdValue, "git checkout -b") == 0 && secondValue == NULL; + deleteTree(&tree); + return result; +} diff --git a/Tree/Tree/TestTree.h b/Tree/Tree/TestTree.h new file mode 100644 index 0000000..f89c36c --- /dev/null +++ b/Tree/Tree/TestTree.h @@ -0,0 +1,14 @@ +#pragma once +#include + +// Function to check the function that adds a node +bool testAddNode(); + +// Function to check the function that deletes the node +bool testDeleteNode(); + +// Function for checking a function that checks for the presence of a key +bool testInTree(); + +// Function for checking a function that gets values by key +bool testGetValue(); \ No newline at end of file diff --git a/Tree/Tree/Tree.c b/Tree/Tree/Tree.c new file mode 100644 index 0000000..8255744 --- /dev/null +++ b/Tree/Tree/Tree.c @@ -0,0 +1,409 @@ +#include "Tree.h" +#include +#include + +typedef struct Node +{ + struct Node* leftSon; + struct Node* rightSon; + struct Node* parent; + int key; + char* value; +} 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); +} + +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; + } +} + +void zig(Node* x) +{ + Node* father = x->parent; + if (x == father->leftSon) + { + Node* rightSon = x->rightSon; + attach(x, father, right); + attach(father, rightSon, left); + } + else + { + Node* leftSon = x->leftSon; + attach(x, father, left); + attach(father, leftSon, right); + } + x->parent = NULL; +} + +void zigZig(Node* x) +{ + Node* father = x->parent; + Node* grandFather = father->parent; + Node* grandGrandFather = grandFather->parent; + if (x == father->leftSon) + { + Node* rightSon = x->rightSon; + Node* bro = father->rightSon; + attach(father, rightSon, left); + attach(grandFather, bro, left); + attach(father, grandFather, right); + attach(x, father, right); + } + else if (x == father->rightSon) + { + Node* leftSon = x->leftSon; + Node* bro = father->leftSon; + attach(father, leftSon, right); + attach(grandFather, bro, right); + attach(father, grandFather, left); + attach(x, father, left); + } + if (grandGrandFather != NULL) + { + if (grandGrandFather->leftSon == grandFather) + { + grandGrandFather->leftSon = x; + } + else if (grandGrandFather->rightSon == grandFather) + { + grandGrandFather->rightSon = x; + } + } + x->parent = grandGrandFather; +} + +void zigZag(Node* x) +{ + Node* father = x->parent; + Node* grandFather = father->parent; + Node* grandGrandFather = grandFather->parent; + if (father->rightSon == x) + { + Node* leftSon = x->leftSon; + Node* rightSon = x->rightSon; + attach(x, father, left); + attach(grandFather, rightSon, left); + attach(father, leftSon, right); + attach(x, grandFather, right); + } + else if (father->leftSon == x) + { + Node* leftSon = x->leftSon; + Node* rightSon = x->rightSon; + attach(x, father, right); + attach(grandFather, leftSon, right); + attach(father, rightSon, left); + attach(x, grandFather, left); + } + if (grandGrandFather != NULL) + { + if (grandGrandFather->leftSon == grandFather) + { + grandGrandFather->leftSon = x; + } + else if (grandGrandFather->rightSon == grandFather) + { + grandGrandFather->rightSon = x; + } + } + x->parent = grandGrandFather; +} + +Node* splay(Node* x) +{ + if (x->parent == NULL) + { + return x; + } + if (x->parent->parent == NULL) + { + zig(x); + return x; + } + if ((x->parent->leftSon == x && x->parent->parent->leftSon == x->parent) + || (x->parent->rightSon == x && x->parent->parent->rightSon == x->parent)) + { + zigZig(x); + } + else + { + zigZag(x); + } + return splay(x); +} + + +Node* addNode(Node* root, int key, char* value) +{ + char* copyValue = calloc(100, sizeof(char)); + if (copyValue == NULL) + { + return NULL; + } + strcpy(copyValue, value); + if (root == NULL) + { + Node* newRoot = (Node*)calloc(1, sizeof(Node)); + if (newRoot == NULL) + { + free(copyValue); + return NULL; + } + newRoot->key = key; + newRoot->value = copyValue; + return newRoot; + } + Node* i = root; + while (i != NULL) + { + if (key > i->key) + { + if (i->rightSon == NULL) + { + Node* newRoot = (Node*)calloc(1, sizeof(Node)); + if (newRoot == NULL) + { + return NULL; + } + newRoot->key = key; + newRoot->value = copyValue; + i->rightSon = newRoot; + newRoot->parent = i; + return splay(newRoot); + } + i = i->rightSon; + } + else if (key == i->key) + { + free(i->value); + i->value = copyValue; + i->key = key; + return splay(i); + } + else + { + if (i->leftSon == NULL) + { + Node* newRoot = (Node*)calloc(1, sizeof(Node)); + if (newRoot == NULL) + { + return NULL; + } + newRoot->key = key; + newRoot->value = copyValue; + i->leftSon = newRoot; + newRoot->parent = i; + return splay(newRoot); + } + i = i->leftSon; + } + } + free(copyValue); + return root; +} + +void search(Node** root, int key) +{ + Node* i = *root; + while (i != NULL) + { + if (key > i->key) + { + i = i->rightSon; + } + else if (key < i->key) + { + i = i->leftSon; + } + else + { + *root = i; + return; + } + } + *root = NULL; +} + +bool inTree(Node* root, int key) +{ + search(&root, key); + if (root == NULL) + { + return false; + } + return true; +} + +Node* deleteNode(Node* root, int key) +{ + search(&root, key); + if (root == NULL) + { + return NULL; + } + if (root->rightSon != NULL && root->leftSon != NULL) + { + Node* i = root; + Node* son = root->leftSon; + root = root->leftSon; + while (root->rightSon != NULL) + { + root = root->rightSon; + } + if (root == i->leftSon) + { + if (i->parent == NULL) + { + i->rightSon->parent = root; + root->rightSon = i->rightSon; + root->parent = NULL; + free(i->value); + free(i); + return root; + } + i->parent->leftSon = i->leftSon; + i->leftSon->parent = i->parent; + free(i); + return splay(root->parent); + } + Node* k = root->parent; + i->key = root->key; + root->parent->rightSon = NULL; + root->parent = NULL; + free(root->value); + free(root); + return splay(k); + } + if (root->rightSon == NULL && root->leftSon == NULL) + { + if (root->parent == NULL) + { + free(root->value); + free(root); + return NULL; + } + else + { + Node* parent = root->parent; + if (root->parent->rightSon == root) + { + root->parent->rightSon = NULL; + root->parent = NULL; + } + else if (root->parent->leftSon == root) + { + root->parent->leftSon = NULL; + root->parent = NULL; + } + free(root->value); + free(root); + return splay(parent); + } + } + if (root->rightSon == NULL && root->leftSon != NULL) + { + if (root->parent == NULL) + { + Node* j = root->leftSon; + root->leftSon->parent = NULL; + root->leftSon = NULL; + free(root->value); + free(root); + return j; + } + Node* parent = root->parent; + root->leftSon->parent = root->parent; + if (root->parent->leftSon == root) + { + root->parent->leftSon = root->leftSon; + } + else if (root->parent->rightSon == root) + { + root->parent->rightSon = root->leftSon; + } + free(root->value); + free(root); + return splay(parent); + } + if (root->rightSon != NULL && root->leftSon == NULL) + { + if (root->parent == NULL) + { + Node* i = root->rightSon; + root->rightSon->parent = NULL; + root->rightSon = NULL; + free(root->value); + free(root); + return i; + } + Node* parent = root->parent; + root->rightSon->parent = root->parent; + if (root->parent->leftSon == root) + { + root->parent->leftSon = root->rightSon; + } + else if (root->parent->rightSon == root) + { + root->parent->rightSon = root->rightSon; + } + free(root->value); + free(root); + return splay(parent); + } + return NULL; +} + +bool isFather(Node* tree, int parentKey, int childKey) +{ + search(&tree, childKey); + return tree->parent->key == parentKey && tree->key == childKey; +} + +char* getValue(Node* root, int key) +{ + search(&root, key); + if (root == NULL) + { + return NULL; + } + return root->value; +} \ No newline at end of file diff --git a/Tree/Tree/Tree.h b/Tree/Tree/Tree.h new file mode 100644 index 0000000..c0ed3cf --- /dev/null +++ b/Tree/Tree/Tree.h @@ -0,0 +1,25 @@ +#include + +// Structure representing a tree +typedef struct Node Node; + +// Function for creating a tree +Node* createTree(); + +// Function for deleting a tree +void deleteTree(Node** root); + +// Function for adding a node +Node* addNode(Node* root, int key, char* value); + +// Function for checking the availability of a key +bool inTree(Node* root, int key); + +// Function for deleting a node +Node* deleteNode(Node* root, int key); + +// Function for checking the node for paternity +bool isFather(Node* tree, int parentKey, int childKey); + +// Function of getting a value by key +char* getValue(Node* root, int key); \ No newline at end of file diff --git a/Tree/Tree/Tree.vcxproj b/Tree/Tree/Tree.vcxproj new file mode 100644 index 0000000..9dcd770 --- /dev/null +++ b/Tree/Tree/Tree.vcxproj @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {1b08b554-064d-4a2d-a418-3c73ff3d4652} + Tree + 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;_CRT_SECURE_NO_WARNINGS;%(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/Tree/Tree/Tree.vcxproj.filters b/Tree/Tree/Tree.vcxproj.filters new file mode 100644 index 0000000..b5b3253 --- /dev/null +++ b/Tree/Tree/Tree.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 From 8d94b3c39ba4f34882c220b74fe5b9d6ba3c257c Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 14 Nov 2021 23:19:29 +0500 Subject: [PATCH 2/6] fixed a function that deletes a tree node --- Tree/Tree/Tree.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Tree/Tree/Tree.c b/Tree/Tree/Tree.c index 8255744..ca78684 100644 --- a/Tree/Tree/Tree.c +++ b/Tree/Tree/Tree.c @@ -307,6 +307,7 @@ Node* deleteNode(Node* root, int key) } Node* k = root->parent; i->key = root->key; + i->value = root->value; root->parent->rightSon = NULL; root->parent = NULL; free(root->value); From e8f39c06773b2d418675d4009a297739cfa863d2 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Thu, 18 Nov 2021 23:36:04 +0300 Subject: [PATCH 3/6] added work with errors, changed the functions of adding and removing nodes --- Tree/Tree/TestTree.c | 60 +++++++------ Tree/Tree/Tree.c | 189 +++++++++++++++++------------------------ Tree/Tree/Tree.h | 12 ++- Tree/Tree/Tree.vcxproj | 2 +- 4 files changed, 121 insertions(+), 142 deletions(-) diff --git a/Tree/Tree/TestTree.c b/Tree/Tree/TestTree.c index 1c46b85..21b7feb 100644 --- a/Tree/Tree/TestTree.c +++ b/Tree/Tree/TestTree.c @@ -4,18 +4,19 @@ bool testAddNode() { + Error error = NOT_ERROR; Node* tree = createTree(); - tree = addNode(tree, 3, "asdadsdsa"); - tree = addNode(tree, 5, "sdadad"); + tree = addNode(tree, 3, "awa", &error); + tree = addNode(tree, 5, "sdadad", &error); bool firstCheck = isFather(tree, 5, 3); - tree = addNode(tree, 1, "wdwddw"); + tree = addNode(tree, 1, "wdwddw", &error); bool secondCheck = isFather(tree, 1, 3); bool thirdCheck = isFather(tree, 3, 5); - tree = addNode(tree, 6, "afwfwfw"); + tree = addNode(tree, 6, "afwfwfw", &error); bool fourthCheck = isFather(tree, 6, 1); bool fifthCheck = isFather(tree, 1, 5); bool sixthCheck = isFather(tree, 5, 3); - tree = addNode(tree, 2, "adwdwd"); + tree = addNode(tree, 2, "adwdwd", &error); bool seventhCheck = isFather(tree, 2, 1); bool eighthCheck = isFather(tree, 2, 6); bool ninthCheck = isFather(tree, 6, 3); @@ -23,37 +24,39 @@ bool testAddNode() deleteTree(&tree); return firstCheck && secondCheck && thirdCheck && fourthCheck && fifthCheck && sixthCheck - && seventhCheck && eighthCheck && ninthCheck && tenthCheck; + && seventhCheck && eighthCheck && ninthCheck && tenthCheck && error == NOT_ERROR; } bool testDeleteNode() { + Error error = NOT_ERROR; Node* tree = createTree(); - tree = addNode(tree, 3, "Hello World"); - tree = addNode(tree, 8, "Hello army"); - tree = addNode(tree, 1, "AVL tree"); - tree = addNode(tree, -8, "^-^"); - tree = addNode(tree, 12, "Test"); - tree = addNode(tree, 2, "git commit"); - tree = deleteNode(tree, 12); + tree = addNode(tree, 3, "Hello World", &error); + tree = addNode(tree, 8, "Hello army", &error); + tree = addNode(tree, 1, "AVL tree", &error); + tree = addNode(tree, -8, "^-^", &error); + tree = addNode(tree, 12, "Test", &error); + tree = addNode(tree, 2, "git commit", &error); + tree = deleteNode(tree, 12, &error); bool firstCheck = inTree(tree, 12); - tree = deleteNode(tree, 1); + tree = deleteNode(tree, 1, &error); bool secondCheck = inTree(tree, 1); - tree = deleteNode(tree, -8); + tree = deleteNode(tree, -8, &error); bool thirdCheck = inTree(tree, -8); deleteTree(&tree); - return !firstCheck && !secondCheck && !thirdCheck; + return !firstCheck && !secondCheck && !thirdCheck && error == NOT_ERROR; } bool testInTree() { + Error error = NOT_ERROR; Node* tree = createTree(); - tree = addNode(tree, 3, "cyclic list"); - tree = addNode(tree, -123, "Memory link"); - tree = addNode(tree, 10, "git checkout -b"); - tree = addNode(tree, -5, "eeeeee"); - tree = addNode(tree, 12, "stormbringer"); - tree = addNode(tree, 2, "i surrender"); + tree = addNode(tree, 3, "cyclic list", &error); + tree = addNode(tree, -123, "Memory link", &error); + tree = addNode(tree, 10, "git checkout -b", &error); + tree = addNode(tree, -5, "eeeeee", &error); + tree = addNode(tree, 12, "stormbringer", &error); + tree = addNode(tree, 2, "i surrender", &error); bool firstCheck = inTree(tree, 3); bool secondCheck = inTree(tree, -5); bool thirdCheck = inTree(tree, 12); @@ -61,27 +64,28 @@ bool testInTree() bool fifthCheck = inTree(tree,-123); bool sixthCheck = inTree(tree, 2021); - tree = deleteNode(tree, 2); + tree = deleteNode(tree, 2, &error); bool seventhCheck = inTree(tree, 2); bool eighthCheck = inTree(tree, 0); - tree = deleteNode(tree, -123); + tree = deleteNode(tree, -123, &error); bool ninthCheck = inTree(tree, -123); bool tenthCheck = inTree(tree, -47); deleteTree(&tree); return firstCheck && secondCheck && thirdCheck && fourthCheck && fifthCheck && !sixthCheck - && !seventhCheck && !eighthCheck && !ninthCheck && !tenthCheck; + && !seventhCheck && !eighthCheck && !ninthCheck && !tenthCheck && error == NOT_ERROR; } bool testGetValue() { + Error error = NOT_ERROR; Node* tree = createTree(); - tree = addNode(tree, 3, "cyclic list"); - tree = addNode(tree, 10, "git checkout -b"); + tree = addNode(tree, 3, "cyclic list", &error); + tree = addNode(tree, 10, "git checkout -b", &error); const char* firstValue = getValue(tree, 3); const char* secondValue = getValue(tree, 4); const char* thirdValue = getValue(tree, 10); - bool result = strcmp(firstValue, "cyclic list") == 0 && strcmp(thirdValue, "git checkout -b") == 0 && secondValue == NULL; + bool result = strcmp(firstValue, "cyclic list") == 0 && strcmp(thirdValue, "git checkout -b") == 0 && secondValue == NULL && error == NOT_ERROR; deleteTree(&tree); return result; } diff --git a/Tree/Tree/Tree.c b/Tree/Tree/Tree.c index ca78684..2071309 100644 --- a/Tree/Tree/Tree.c +++ b/Tree/Tree/Tree.c @@ -172,22 +172,28 @@ Node* splay(Node* x) } -Node* addNode(Node* root, int key, char* value) +Node* addNode(Node* root, int key, const char* value, Error* error) { - char* copyValue = calloc(100, sizeof(char)); + if (*error != NOT_ERROR) + { + return root; + } + char* copyValue = calloc(strlen(value) + 1, sizeof(char)); if (copyValue == NULL) { - return NULL; + *error = INSUFFICIENT_MEMORY; + return root; } strcpy(copyValue, value); + Node* newRoot = (Node*)calloc(1, sizeof(Node)); + if (newRoot == NULL) + { + *error = INSUFFICIENT_MEMORY; + free(copyValue); + return root; + } if (root == NULL) { - Node* newRoot = (Node*)calloc(1, sizeof(Node)); - if (newRoot == NULL) - { - free(copyValue); - return NULL; - } newRoot->key = key; newRoot->value = copyValue; return newRoot; @@ -199,11 +205,6 @@ Node* addNode(Node* root, int key, char* value) { if (i->rightSon == NULL) { - Node* newRoot = (Node*)calloc(1, sizeof(Node)); - if (newRoot == NULL) - { - return NULL; - } newRoot->key = key; newRoot->value = copyValue; i->rightSon = newRoot; @@ -223,11 +224,6 @@ Node* addNode(Node* root, int key, char* value) { if (i->leftSon == NULL) { - Node* newRoot = (Node*)calloc(1, sizeof(Node)); - if (newRoot == NULL) - { - return NULL; - } newRoot->key = key; newRoot->value = copyValue; i->leftSon = newRoot; @@ -237,6 +233,7 @@ Node* addNode(Node* root, int key, char* value) i = i->leftSon; } } + free(newRoot); free(copyValue); return root; } @@ -266,131 +263,101 @@ void search(Node** root, int key) bool inTree(Node* root, int key) { search(&root, key); - if (root == NULL) - { - return false; - } - return true; + return root != NULL; } -Node* deleteNode(Node* root, int key) +Node* deleteNode(Node* root, int key, Error* error) { + if (*error != NOT_ERROR) + { + return root; + } search(&root, key); if (root == NULL) { - return NULL; + *error = ROOT_IS_MISSING; + return root; } - if (root->rightSon != NULL && root->leftSon != NULL) + if (root->rightSon == NULL && root->leftSon == NULL) { - Node* i = root; - Node* son = root->leftSon; - root = root->leftSon; - while (root->rightSon != NULL) - { - root = root->rightSon; - } - if (root == i->leftSon) + Node* parent = root->parent; + if (parent != NULL) { - if (i->parent == NULL) + if (root->parent->rightSon == root) + { + root->parent->rightSon = NULL; + } + else { - i->rightSon->parent = root; - root->rightSon = i->rightSon; - root->parent = NULL; - free(i->value); - free(i); - return root; + root->parent->leftSon = NULL; } - i->parent->leftSon = i->leftSon; - i->leftSon->parent = i->parent; - free(i); - return splay(root->parent); } - Node* k = root->parent; - i->key = root->key; - i->value = root->value; - root->parent->rightSon = NULL; - root->parent = NULL; free(root->value); free(root); - return splay(k); + return (parent == NULL) ? NULL : splay(parent); } - if (root->rightSon == NULL && root->leftSon == NULL) + if (root->rightSon != NULL && root->leftSon != NULL) { - if (root->parent == NULL) + Node* currentRoot = root; + currentRoot = currentRoot->leftSon; + while (currentRoot->rightSon != NULL) { - free(root->value); - free(root); - return NULL; + currentRoot = currentRoot->rightSon; } - else + if (currentRoot == root->leftSon) { Node* parent = root->parent; - if (root->parent->rightSon == root) + parent == NULL ? attach(currentRoot, root->rightSon, right) + : attach(root->parent, root->leftSon, left); + if (parent == NULL) { - root->parent->rightSon = NULL; - root->parent = NULL; - } - else if (root->parent->leftSon == root) - { - root->parent->leftSon = NULL; - root->parent = NULL; + currentRoot->parent = NULL; } free(root->value); free(root); - return splay(parent); + return parent == NULL ? currentRoot : splay(currentRoot->parent); } - } - if (root->rightSon == NULL && root->leftSon != NULL) - { - if (root->parent == NULL) + Node* currentRootParent = currentRoot->parent; + root->key = currentRoot->key; + char* newValue = calloc(strlen(root->value) + 1, sizeof(char)); + if (newValue == NULL) { - Node* j = root->leftSon; - root->leftSon->parent = NULL; - root->leftSon = NULL; - free(root->value); - free(root); - return j; - } - Node* parent = root->parent; - root->leftSon->parent = root->parent; - if (root->parent->leftSon == root) - { - root->parent->leftSon = root->leftSon; - } - else if (root->parent->rightSon == root) - { - root->parent->rightSon = root->leftSon; + *error = INSUFFICIENT_MEMORY; + return root; } free(root->value); - free(root); - return splay(parent); + strcpy(newValue, currentRoot->value); + root->value = newValue; + currentRootParent->rightSon = NULL; + free(currentRoot->value); + free(currentRoot); + return splay(currentRootParent); } - if (root->rightSon != NULL && root->leftSon == NULL) + if (root->parent == NULL) { - if (root->parent == NULL) - { - Node* i = root->rightSon; - root->rightSon->parent = NULL; - root->rightSon = NULL; - free(root->value); - free(root); - return i; - } - Node* parent = root->parent; - root->rightSon->parent = root->parent; - if (root->parent->leftSon == root) - { - root->parent->leftSon = root->rightSon; - } - else if (root->parent->rightSon == root) + root = root->rightSon == NULL ? root->leftSon : root->rightSon; + if (root->parent != NULL) { - root->parent->rightSon = root->rightSon; + free(root->parent->value); } - free(root->value); - free(root); - return splay(parent); + free(root->parent); + root->parent = NULL; + return root; } - return NULL; + Node* parent = root->parent; + if (root->rightSon == NULL) + { + parent->leftSon == root ? attach(parent,root->leftSon,left) + : attach(parent,root->leftSon, right); + } + else + { + parent->leftSon == root ? attach(parent, root->rightSon, left) + : attach(parent, root->rightSon, right); + } + free(root->value); + free(root); + return splay(parent); } bool isFather(Node* tree, int parentKey, int childKey) diff --git a/Tree/Tree/Tree.h b/Tree/Tree/Tree.h index c0ed3cf..2ccd2d9 100644 --- a/Tree/Tree/Tree.h +++ b/Tree/Tree/Tree.h @@ -3,6 +3,14 @@ // Structure representing a tree typedef struct Node Node; +// Structure representing a tree +typedef enum Error +{ + NOT_ERROR, + ROOT_IS_MISSING, + INSUFFICIENT_MEMORY +} Error; + // Function for creating a tree Node* createTree(); @@ -10,13 +18,13 @@ Node* createTree(); void deleteTree(Node** root); // Function for adding a node -Node* addNode(Node* root, int key, char* value); +Node* addNode(Node* root, int key, const char* value, Error* error); // Function for checking the availability of a key bool inTree(Node* root, int key); // Function for deleting a node -Node* deleteNode(Node* root, int key); +Node* deleteNode(Node* root, int key, Error* error); // Function for checking the node for paternity bool isFather(Node* tree, int parentKey, int childKey); diff --git a/Tree/Tree/Tree.vcxproj b/Tree/Tree/Tree.vcxproj index 9dcd770..1f66300 100644 --- a/Tree/Tree/Tree.vcxproj +++ b/Tree/Tree/Tree.vcxproj @@ -114,7 +114,7 @@ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true From 9aab49197bc4d3687d640ac9196a40345d7c067f Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Thu, 18 Nov 2021 23:40:40 +0300 Subject: [PATCH 4/6] deleting unnecessary files --- "Homework \342\204\2261/Array/Array.sln" | 31 --- "Homework \342\204\2261/Array/Array/Array.c" | 18 -- .../Array/Array/Array.vcxproj" | 147 ------------ .../Array/Array/Array.vcxproj.filters" | 22 -- "Homework \342\204\2261/Balance/Balance.sln" | 31 --- .../Balance/Balance/Balance.vcxproj" | 147 ------------ .../Balance/Balance/Balance.vcxproj.filters" | 22 -- .../Balance/Balance/balance.c" | 33 --- .../Division/Division.sln" | 31 --- .../Division/Division/Division.c" | 84 ------- .../Division/Division/Division.vcxproj" | 147 ------------ .../Division/Division.vcxproj.filters" | 22 -- "Homework \342\204\2261/Number/Number.sln" | 31 --- .../Number/Number/Number.c" | 35 --- .../Number/Number/Number.vcxproj" | 147 ------------ .../Number/Number/Number.vcxproj.filters" | 22 -- .../Ssection/Ssection.sln" | 31 --- .../Ssection/Ssection/Section.c" | 46 ---- .../Ssection/Ssection/Ssection.vcxproj" | 147 ------------ .../Ssection/Ssection.vcxproj.filters" | 22 -- "Homework \342\204\2261/String/String.sln" | 31 --- .../String/String/String.c" | 57 ----- .../String/String/String.vcxproj" | 147 ------------ .../String/String/String.vcxproj.filters" | 22 -- "Homework \342\204\2261/Swap/Swap.sln" | 31 --- "Homework \342\204\2261/Swap/Swap/Swap.c" | 15 -- .../Swap/Swap/Swap.vcxproj" | 147 ------------ .../Swap/Swap/Swap.vcxproj.filters" | 22 -- "Homework \342\204\2261/Tickets/Tickets.sln" | 31 --- .../Tickets/Tickets/Tickets.c" | 32 --- .../Tickets/Tickets/Tickets.vcxproj" | 147 ------------ .../Tickets/Tickets/Tickets.vcxproj.filters" | 22 -- .../CountAndBubbleSort.sln" | 31 --- .../CountAndBubbleSort/CountAndBubbleSort.c" | 214 ------------------ .../CountAndBubbleSort.vcxproj" | 147 ------------ .../CountAndBubbleSort.vcxproj.filters" | 22 -- .../CountAndBubbleSort.vcxproj.user" | 4 - "Homework \342\204\2262/Extent/Extent.sln" | 31 --- .../Extent/Extent/Extent.vcxproj" | 148 ------------ .../Extent/Extent/Extent.vcxproj.filters" | 22 -- .../Extent/Extent/Extent.vcxproj.user" | 4 - .../Extent/Extent/extent.c" | 117 ---------- .../Fibonacci/Fibonacci.sln" | 31 --- .../Fibonacci/Fibonacci/Fibonacci.c" | 79 ------- .../Fibonacci/Fibonacci/Fibonacci.vcxproj" | 147 ------------ .../Fibonacci/Fibonacci.vcxproj.filters" | 22 -- .../Fibonacci/Fibonacci.vcxproj.user" | 4 - .../semiQSort/semiQSort.sln" | 31 --- .../semiQSort/semiQSort/semiQSort.c" | 119 ---------- .../semiQSort/semiQSort/semiQSort.vcxproj" | 147 ------------ .../semiQSort/semiQSort.vcxproj.filters" | 22 -- .../semiQSort/semiQSort.vcxproj.user" | 4 - .../binarySearch/binarySearch.sln" | 31 --- .../binarySearch/binarySearch/binary.h" | 8 - .../binarySearch/binarySearch/binarySearch.c" | 61 ----- .../binarySearch/binarySearch.vcxproj" | 153 ------------- .../binarySearch.vcxproj.filters" | 36 --- .../binarySearch/binarySearch/main.c" | 36 --- .../binarySearch/binarySearch/qsort.c" | 107 --------- .../binarySearch/binarySearch/qsort.h" | 15 -- .../quickSort/quickSort.sln" | 31 --- .../quickSort/quickSort/quickSort.vcxproj" | 147 ------------ .../quickSort/quickSort.vcxproj.filters" | 22 -- .../quickSort/quickSort/quicksort.c" | 136 ----------- .../theMostCommonElement.sln" | 31 --- .../TheMostCommonElement.c" | 33 --- .../TheMostCommonElement.h" | 4 - .../theMostCommonElement/main.c" | 28 --- .../theMostCommonElement/qsort.c" | 64 ------ .../theMostCommonElement/qsort.h" | 4 - .../theMostCommonElement/test.h" | 8 - .../theMostCommonElement/tests.c" | 70 ------ .../theMostCommonElement.vcxproj" | 155 ------------- .../theMostCommonElement.vcxproj.filters" | 42 ---- .../Phonebook/Phonebook.sln" | 31 --- .../Phonebook/Phonebook/Phonebook.vcxproj" | 153 ------------- .../Phonebook/Phonebook.vcxproj.filters" | 36 --- .../Phonebook/Phonebook/main.c" | 128 ----------- .../Phonebook/Phonebook/phoneBook.c" | 90 -------- .../Phonebook/Phonebook/phoneBook.h" | 27 --- .../Phonebook/Phonebook/phoneNumber.txt" | 19 -- .../Phonebook/Phonebook/test1.txt" | 4 - .../Phonebook/Phonebook/tests.c" | 34 --- .../Phonebook/Phonebook/tests.h" | 5 - .../additionOfNumbers/additionOfNumbers.sln" | 31 --- .../additionOfNumbers.vcxproj" | 153 ------------- .../additionOfNumbers.vcxproj.filters" | 36 --- .../additionOfNumbers/binaryNumberSystem.c" | 49 ---- .../additionOfNumbers/binaryNumberSystem.h" | 14 -- .../additionOfNumbers/main.c" | 48 ---- .../additionOfNumbers/tests.c" | 67 ------ .../additionOfNumbers/tests.h" | 11 - 92 files changed, 5424 deletions(-) delete mode 100644 "Homework \342\204\2261/Array/Array.sln" delete mode 100644 "Homework \342\204\2261/Array/Array/Array.c" delete mode 100644 "Homework \342\204\2261/Array/Array/Array.vcxproj" delete mode 100644 "Homework \342\204\2261/Array/Array/Array.vcxproj.filters" delete mode 100644 "Homework \342\204\2261/Balance/Balance.sln" delete mode 100644 "Homework \342\204\2261/Balance/Balance/Balance.vcxproj" delete mode 100644 "Homework \342\204\2261/Balance/Balance/Balance.vcxproj.filters" delete mode 100644 "Homework \342\204\2261/Balance/Balance/balance.c" delete mode 100644 "Homework \342\204\2261/Division/Division.sln" delete mode 100644 "Homework \342\204\2261/Division/Division/Division.c" delete mode 100644 "Homework \342\204\2261/Division/Division/Division.vcxproj" delete mode 100644 "Homework \342\204\2261/Division/Division/Division.vcxproj.filters" delete mode 100644 "Homework \342\204\2261/Number/Number.sln" delete mode 100644 "Homework \342\204\2261/Number/Number/Number.c" delete mode 100644 "Homework \342\204\2261/Number/Number/Number.vcxproj" delete mode 100644 "Homework \342\204\2261/Number/Number/Number.vcxproj.filters" delete mode 100644 "Homework \342\204\2261/Ssection/Ssection.sln" delete mode 100644 "Homework \342\204\2261/Ssection/Ssection/Section.c" delete mode 100644 "Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj" delete mode 100644 "Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj.filters" delete mode 100644 "Homework \342\204\2261/String/String.sln" delete mode 100644 "Homework \342\204\2261/String/String/String.c" delete mode 100644 "Homework \342\204\2261/String/String/String.vcxproj" delete mode 100644 "Homework \342\204\2261/String/String/String.vcxproj.filters" delete mode 100644 "Homework \342\204\2261/Swap/Swap.sln" delete mode 100644 "Homework \342\204\2261/Swap/Swap/Swap.c" delete mode 100644 "Homework \342\204\2261/Swap/Swap/Swap.vcxproj" delete mode 100644 "Homework \342\204\2261/Swap/Swap/Swap.vcxproj.filters" delete mode 100644 "Homework \342\204\2261/Tickets/Tickets.sln" delete mode 100644 "Homework \342\204\2261/Tickets/Tickets/Tickets.c" delete mode 100644 "Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj" delete mode 100644 "Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj.filters" delete mode 100644 "Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort.sln" delete mode 100644 "Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.c" delete mode 100644 "Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj" delete mode 100644 "Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.filters" delete mode 100644 "Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.user" delete mode 100644 "Homework \342\204\2262/Extent/Extent.sln" delete mode 100644 "Homework \342\204\2262/Extent/Extent/Extent.vcxproj" delete mode 100644 "Homework \342\204\2262/Extent/Extent/Extent.vcxproj.filters" delete mode 100644 "Homework \342\204\2262/Extent/Extent/Extent.vcxproj.user" delete mode 100644 "Homework \342\204\2262/Extent/Extent/extent.c" delete mode 100644 "Homework \342\204\2262/Fibonacci/Fibonacci.sln" delete mode 100644 "Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.c" delete mode 100644 "Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj" delete mode 100644 "Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.filters" delete mode 100644 "Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.user" delete mode 100644 "Homework \342\204\2262/semiQSort/semiQSort.sln" delete mode 100644 "Homework \342\204\2262/semiQSort/semiQSort/semiQSort.c" delete mode 100644 "Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj" delete mode 100644 "Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.filters" delete mode 100644 "Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.user" delete mode 100644 "Homework \342\204\2263/binarySearch/binarySearch.sln" delete mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/binary.h" delete mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/binarySearch.c" delete mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj" delete mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj.filters" delete mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/main.c" delete mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/qsort.c" delete mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/qsort.h" delete mode 100644 "Homework \342\204\2263/quickSort/quickSort.sln" delete mode 100644 "Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj" delete mode 100644 "Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj.filters" delete mode 100644 "Homework \342\204\2263/quickSort/quickSort/quicksort.c" delete mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement.sln" delete mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.c" delete mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.h" delete mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/main.c" delete mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.c" delete mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.h" delete mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/test.h" delete mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/tests.c" delete mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj" delete mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj.filters" delete mode 100644 "Homework \342\204\2264/Phonebook/Phonebook.sln" delete mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj" delete mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj.filters" delete mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/main.c" delete mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/phoneBook.c" delete mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/phoneBook.h" delete mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/phoneNumber.txt" delete mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/test1.txt" delete mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/tests.c" delete mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/tests.h" delete mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers.sln" delete mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj" delete mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj.filters" delete mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.c" delete mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.h" delete mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/main.c" delete mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.c" delete mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.h" diff --git "a/Homework \342\204\2261/Array/Array.sln" "b/Homework \342\204\2261/Array/Array.sln" deleted file mode 100644 index 1575323..0000000 --- "a/Homework \342\204\2261/Array/Array.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "Array", "Array\Array.vcxproj", "{237C1E80-EEBB-4E9D-8754-268C34E50000}" -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 - {237C1E80-EEBB-4E9D-8754-268C34E50000}.Debug|x64.ActiveCfg = Debug|x64 - {237C1E80-EEBB-4E9D-8754-268C34E50000}.Debug|x64.Build.0 = Debug|x64 - {237C1E80-EEBB-4E9D-8754-268C34E50000}.Debug|x86.ActiveCfg = Debug|Win32 - {237C1E80-EEBB-4E9D-8754-268C34E50000}.Debug|x86.Build.0 = Debug|Win32 - {237C1E80-EEBB-4E9D-8754-268C34E50000}.Release|x64.ActiveCfg = Release|x64 - {237C1E80-EEBB-4E9D-8754-268C34E50000}.Release|x64.Build.0 = Release|x64 - {237C1E80-EEBB-4E9D-8754-268C34E50000}.Release|x86.ActiveCfg = Release|Win32 - {237C1E80-EEBB-4E9D-8754-268C34E50000}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {9DF372F6-37E4-4FE8-B6E3-CFF5D4A7944B} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2261/Array/Array/Array.c" "b/Homework \342\204\2261/Array/Array/Array.c" deleted file mode 100644 index 8619d13..0000000 --- "a/Homework \342\204\2261/Array/Array/Array.c" +++ /dev/null @@ -1,18 +0,0 @@ -#include - -int main() -{ - int arrayOfNumbers[100] = {0}; - int numberZeroValues = 0; - for (int i = 0; i < 100; i++) - { - // we assign random values from 0 to 9 to the elements of the array - arrayOfNumbers[i] = rand() % 10; - // if the value of an array element is 0, we increase the counter of zero elements by 1 - if (arrayOfNumbers[i] == 0) - { - numberZeroValues++; - } - } - printf("The number of zero elements in the array = %d", numberZeroValues); -} \ No newline at end of file diff --git "a/Homework \342\204\2261/Array/Array/Array.vcxproj" "b/Homework \342\204\2261/Array/Array/Array.vcxproj" deleted file mode 100644 index 34969d4..0000000 --- "a/Homework \342\204\2261/Array/Array/Array.vcxproj" +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {237c1e80-eebb-4e9d-8754-268c34e50000} - Array - 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/Homework \342\204\2261/Array/Array/Array.vcxproj.filters" "b/Homework \342\204\2261/Array/Array/Array.vcxproj.filters" deleted file mode 100644 index 782aede..0000000 --- "a/Homework \342\204\2261/Array/Array/Array.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2261/Balance/Balance.sln" "b/Homework \342\204\2261/Balance/Balance.sln" deleted file mode 100644 index f2e3e26..0000000 --- "a/Homework \342\204\2261/Balance/Balance.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "Balance", "Balance\Balance.vcxproj", "{3372BD3C-C97A-432C-8601-2B136B61FC99}" -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 - {3372BD3C-C97A-432C-8601-2B136B61FC99}.Debug|x64.ActiveCfg = Debug|x64 - {3372BD3C-C97A-432C-8601-2B136B61FC99}.Debug|x64.Build.0 = Debug|x64 - {3372BD3C-C97A-432C-8601-2B136B61FC99}.Debug|x86.ActiveCfg = Debug|Win32 - {3372BD3C-C97A-432C-8601-2B136B61FC99}.Debug|x86.Build.0 = Debug|Win32 - {3372BD3C-C97A-432C-8601-2B136B61FC99}.Release|x64.ActiveCfg = Release|x64 - {3372BD3C-C97A-432C-8601-2B136B61FC99}.Release|x64.Build.0 = Release|x64 - {3372BD3C-C97A-432C-8601-2B136B61FC99}.Release|x86.ActiveCfg = Release|Win32 - {3372BD3C-C97A-432C-8601-2B136B61FC99}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {06E3F097-DF24-4285-ABF2-0EF1902D316E} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2261/Balance/Balance/Balance.vcxproj" "b/Homework \342\204\2261/Balance/Balance/Balance.vcxproj" deleted file mode 100644 index b67bee6..0000000 --- "a/Homework \342\204\2261/Balance/Balance/Balance.vcxproj" +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {3372bd3c-c97a-432c-8601-2b136b61fc99} - Balance - 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/Homework \342\204\2261/Balance/Balance/Balance.vcxproj.filters" "b/Homework \342\204\2261/Balance/Balance/Balance.vcxproj.filters" deleted file mode 100644 index 3ec152a..0000000 --- "a/Homework \342\204\2261/Balance/Balance/Balance.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2261/Balance/Balance/balance.c" "b/Homework \342\204\2261/Balance/Balance/balance.c" deleted file mode 100644 index 7b3c065..0000000 --- "a/Homework \342\204\2261/Balance/Balance/balance.c" +++ /dev/null @@ -1,33 +0,0 @@ -#include - -int main() -{ - char stringBrackets[100] = {'\0'}; - gets(stringBrackets); - int counterBrakets = 0; - int counterCycle = 0; - - while(counterBrakets >= 0 && stringBrackets[counterCycle] != '\0') - { - // if the bracket is opening, then we increase the counter value by 1 - if (stringBrackets[counterCycle] == '(') - { - counterBrakets++; - } - // otherwise, we reduce the counter value by 1 - else if (stringBrackets[counterCycle] == ')') - { - counterBrakets--; - } - counterCycle++; - } - - if (counterBrakets == 0) - { - printf("The rule of nesting brackets is observed."); - } - else - { - printf("The rule of nesting brackets is not observed."); - } -} \ No newline at end of file diff --git "a/Homework \342\204\2261/Division/Division.sln" "b/Homework \342\204\2261/Division/Division.sln" deleted file mode 100644 index 2f0a2d8..0000000 --- "a/Homework \342\204\2261/Division/Division.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "Division", "Division\Division.vcxproj", "{E1AB46C9-95F5-4284-9487-B90A7AE1B785}" -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 - {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Debug|x64.ActiveCfg = Debug|x64 - {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Debug|x64.Build.0 = Debug|x64 - {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Debug|x86.ActiveCfg = Debug|Win32 - {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Debug|x86.Build.0 = Debug|Win32 - {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Release|x64.ActiveCfg = Release|x64 - {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Release|x64.Build.0 = Release|x64 - {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Release|x86.ActiveCfg = Release|Win32 - {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {060FAA4C-3486-4299-86E2-282A3924D91E} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2261/Division/Division/Division.c" "b/Homework \342\204\2261/Division/Division/Division.c" deleted file mode 100644 index 4e35eac..0000000 --- "a/Homework \342\204\2261/Division/Division/Division.c" +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include - -void printQuotientDivision(int counter) -{ - printf("quotient of division = %d", counter); -} - -int main() -{ - int a = 0; - int b = 0; - printf("enter dividend \n"); - const int firstScanfResultA = scanf_s("%d", &a); - if (firstScanfResultA == 0) - { - printf("had to enter a number"); - return 0; - } - - printf("enter the divisor\n"); - const int firstScanfResultB = scanf_s("%d", &b); - if (!firstScanfResultB) - { - printf("had to enter a number"); - return 0; - } - - if (b == 0) - { - printf("you can't divide by 0"); - return 0; - } - - if (a == 0 && b!= 0) - { - printQuotientDivision(0); - return 0; - } - - if (a == b) - { - printQuotientDivision(1); - return 0; - } - - if (a == -b) - { - printQuotientDivision(-1); - return 0; - } - - int subtractionounter = 0; - int absoluteValueA = abs(a); - int absoluteValueB = abs(b); - - while (absoluteValueA - absoluteValueB > 0) - { - absoluteValueA -= absoluteValueB; - subtractionounter++; - } - - if (a > 0 && b < 0) - { - printQuotientDivision(-subtractionounter); - } - - if (a < 0 && b > 0) - { - printQuotientDivision(-subtractionounter - 1); - } - - if (a > 0 && b > 0) - { - printQuotientDivision(subtractionounter); - } - - if (a < 0 && b < 0) - { - printQuotientDivision(subtractionounter + 1); - } - - return 0; -} \ No newline at end of file diff --git "a/Homework \342\204\2261/Division/Division/Division.vcxproj" "b/Homework \342\204\2261/Division/Division/Division.vcxproj" deleted file mode 100644 index fa75c2f..0000000 --- "a/Homework \342\204\2261/Division/Division/Division.vcxproj" +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {e1ab46c9-95f5-4284-9487-b90a7ae1b785} - Division - 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/Homework \342\204\2261/Division/Division/Division.vcxproj.filters" "b/Homework \342\204\2261/Division/Division/Division.vcxproj.filters" deleted file mode 100644 index 77eca4f..0000000 --- "a/Homework \342\204\2261/Division/Division/Division.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2261/Number/Number.sln" "b/Homework \342\204\2261/Number/Number.sln" deleted file mode 100644 index e64c8c6..0000000 --- "a/Homework \342\204\2261/Number/Number.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "Number", "Number\Number.vcxproj", "{06765B58-98FC-456B-AA35-559A61EC159D}" -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 - {06765B58-98FC-456B-AA35-559A61EC159D}.Debug|x64.ActiveCfg = Debug|x64 - {06765B58-98FC-456B-AA35-559A61EC159D}.Debug|x64.Build.0 = Debug|x64 - {06765B58-98FC-456B-AA35-559A61EC159D}.Debug|x86.ActiveCfg = Debug|Win32 - {06765B58-98FC-456B-AA35-559A61EC159D}.Debug|x86.Build.0 = Debug|Win32 - {06765B58-98FC-456B-AA35-559A61EC159D}.Release|x64.ActiveCfg = Release|x64 - {06765B58-98FC-456B-AA35-559A61EC159D}.Release|x64.Build.0 = Release|x64 - {06765B58-98FC-456B-AA35-559A61EC159D}.Release|x86.ActiveCfg = Release|Win32 - {06765B58-98FC-456B-AA35-559A61EC159D}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {DFE5B96D-0446-4BDB-B38F-FFDCF0D327CE} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2261/Number/Number/Number.c" "b/Homework \342\204\2261/Number/Number/Number.c" deleted file mode 100644 index 913549c..0000000 --- "a/Homework \342\204\2261/Number/Number/Number.c" +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include - -int main() -{ - int number = 0; - printf("Enter a positive integer\n"); - scanf_s("%d", &number); - // if the number is non-positive, then it has no divisors - if (number <= 0) - { - printf("It was necessary to enter a positive number"); - return 0; - } - // brute force for numbers from 1 to number - for (int i = 1; i <= number; i++) - { - const int rootOfTheNumber = sqrt(i); - // for each i, we are looking for divisors from 1 to sqrt(i) - for (int j = 1; j <= rootOfTheNumber; j++) - { - // if a number from 1 to number has a divisor j that is not equal to 1, then this number is composite - if (i % j == 0 && j != 1) - { - // since the number is composite, it makes no sense to look for its other divisors, exit the loop - break; - } - // we continue until j is equal to the number floor(sqrt(i)) (in this case, the number is prime) - if (j == floor(sqrt(i))) - { - printf("%d\n", i); - } - } - } -} \ No newline at end of file diff --git "a/Homework \342\204\2261/Number/Number/Number.vcxproj" "b/Homework \342\204\2261/Number/Number/Number.vcxproj" deleted file mode 100644 index 7c803a3..0000000 --- "a/Homework \342\204\2261/Number/Number/Number.vcxproj" +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {06765b58-98fc-456b-aa35-559a61ec159d} - Number - 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/Homework \342\204\2261/Number/Number/Number.vcxproj.filters" "b/Homework \342\204\2261/Number/Number/Number.vcxproj.filters" deleted file mode 100644 index 6afdaa3..0000000 --- "a/Homework \342\204\2261/Number/Number/Number.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2261/Ssection/Ssection.sln" "b/Homework \342\204\2261/Ssection/Ssection.sln" deleted file mode 100644 index 3745e20..0000000 --- "a/Homework \342\204\2261/Ssection/Ssection.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "Ssection", "Ssection\Ssection.vcxproj", "{B24E5472-F4B3-4E47-A7FA-60D3037367CF}" -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 - {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Debug|x64.ActiveCfg = Debug|x64 - {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Debug|x64.Build.0 = Debug|x64 - {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Debug|x86.ActiveCfg = Debug|Win32 - {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Debug|x86.Build.0 = Debug|Win32 - {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Release|x64.ActiveCfg = Release|x64 - {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Release|x64.Build.0 = Release|x64 - {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Release|x86.ActiveCfg = Release|Win32 - {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {1F3DCF66-94B1-4620-B212-A22A95DEC463} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2261/Ssection/Ssection/Section.c" "b/Homework \342\204\2261/Ssection/Ssection/Section.c" deleted file mode 100644 index 0f7ba39..0000000 --- "a/Homework \342\204\2261/Ssection/Ssection/Section.c" +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include - -// A function for inverting array values that depends on the number of the first element in the segment and the number of elements in the array -void flipNumbersArray(int firstElement, int numberOfElements, int* arrayOfNumbers) -{ - for (int i = firstElement; i < numberOfElements / 2; i++) - { - const int temporary = arrayOfNumbers[i]; - arrayOfNumbers[i] = arrayOfNumbers[numberOfElements - 1 - i]; - arrayOfNumbers[numberOfElements - 1 - i] = temporary; - } -} - -void printNumbersArray(int numberOfElements, int* arrayOfNumbers) -{ - for (int i = 0; i < numberOfElements; i++) - { - printf(" %d", arrayOfNumbers[i]); - } -} - -int main() -{ - int numberOfElements = 0; - printf("Enter the number of elements in the array\n"); - scanf_s("%d", &numberOfElements); - // allocation of dynamic memory for entering the number of elements in the array from the keyboard - int* arrayOfNumbers = (int*)malloc(numberOfElements * sizeof(int)); - printf("The segment of what length do you want to move to the end?\n"); - int m = 0; - scanf_s("%d", &m); - - for (int i = 0; i < numberOfElements; i++) - { - arrayOfNumbers[i] = rand() % 10; - } - - printNumbersArray(numberOfElements, arrayOfNumbers); - flipNumbersArray(0, m, arrayOfNumbers); - flipNumbersArray(m, numberOfElements + m, arrayOfNumbers); - flipNumbersArray(0, numberOfElements , arrayOfNumbers); - printf("\n\n\n"); - printNumbersArray(numberOfElements, arrayOfNumbers); - free(arrayOfNumbers); -} diff --git "a/Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj" "b/Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj" deleted file mode 100644 index df1cd23..0000000 --- "a/Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj" +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {b24e5472-f4b3-4e47-a7fa-60d3037367cf} - Ssection - 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/Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj.filters" "b/Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj.filters" deleted file mode 100644 index 0b4a350..0000000 --- "a/Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2261/String/String.sln" "b/Homework \342\204\2261/String/String.sln" deleted file mode 100644 index 1a0c6a9..0000000 --- "a/Homework \342\204\2261/String/String.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "String", "String\String.vcxproj", "{F28DB431-02D6-423A-AD87-08796F891FA1}" -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 - {F28DB431-02D6-423A-AD87-08796F891FA1}.Debug|x64.ActiveCfg = Debug|x64 - {F28DB431-02D6-423A-AD87-08796F891FA1}.Debug|x64.Build.0 = Debug|x64 - {F28DB431-02D6-423A-AD87-08796F891FA1}.Debug|x86.ActiveCfg = Debug|Win32 - {F28DB431-02D6-423A-AD87-08796F891FA1}.Debug|x86.Build.0 = Debug|Win32 - {F28DB431-02D6-423A-AD87-08796F891FA1}.Release|x64.ActiveCfg = Release|x64 - {F28DB431-02D6-423A-AD87-08796F891FA1}.Release|x64.Build.0 = Release|x64 - {F28DB431-02D6-423A-AD87-08796F891FA1}.Release|x86.ActiveCfg = Release|Win32 - {F28DB431-02D6-423A-AD87-08796F891FA1}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {D33770E3-4529-4E2C-898F-05D35A9758E0} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2261/String/String/String.c" "b/Homework \342\204\2261/String/String/String.c" deleted file mode 100644 index 5a9c416..0000000 --- "a/Homework \342\204\2261/String/String/String.c" +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include - -int main() -{ - setlocale(LC_ALL, "Rus"); - int matchingSymbolsCount = 0; - int occurrencesCount = 0; - char s[100] = {'\0'}; - char s1[100] = {'\0'}; - printf(" S "); - gets(s); - printf(" S1 "); - gets(s1); - // S - const int lineLengthS = strlen(s); - // S1 - const int lineLengthS1 = strlen(s1); - - // S1 > S - if (lineLengthS / lineLengthS1 < 1) - { - printf(" s1 = 0"); - return 0; - } - - for (int i = 0; i < lineLengthS - lineLengthS1 + 1; i++) - { - // S S1 - if (s[i] == s1[0]) - { - // - for (int l = 0; l <= lineLengthS1 - 1; l++) - { - if (s[i + l] == s1[l]) - { - // - matchingSymbolsCount++; - - // S1, 1 - if (matchingSymbolsCount == lineLengthS1) - { - occurrencesCount++; - matchingSymbolsCount = 0; - } - } - else - { - break; - } - } - } - } - printf(" S1 = %d", occurrencesCount); - return 0; -} \ No newline at end of file diff --git "a/Homework \342\204\2261/String/String/String.vcxproj" "b/Homework \342\204\2261/String/String/String.vcxproj" deleted file mode 100644 index 0c995da..0000000 --- "a/Homework \342\204\2261/String/String/String.vcxproj" +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {f28db431-02d6-423a-ad87-08796f891fa1} - String - 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/Homework \342\204\2261/String/String/String.vcxproj.filters" "b/Homework \342\204\2261/String/String/String.vcxproj.filters" deleted file mode 100644 index 00be40e..0000000 --- "a/Homework \342\204\2261/String/String/String.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2261/Swap/Swap.sln" "b/Homework \342\204\2261/Swap/Swap.sln" deleted file mode 100644 index 0b5a831..0000000 --- "a/Homework \342\204\2261/Swap/Swap.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "Swap", "Swap\Swap.vcxproj", "{9A76EFB7-28EE-4317-AD9F-BB16463A313E}" -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 - {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Debug|x64.ActiveCfg = Debug|x64 - {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Debug|x64.Build.0 = Debug|x64 - {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Debug|x86.ActiveCfg = Debug|Win32 - {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Debug|x86.Build.0 = Debug|Win32 - {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Release|x64.ActiveCfg = Release|x64 - {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Release|x64.Build.0 = Release|x64 - {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Release|x86.ActiveCfg = Release|Win32 - {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {CD05E673-AD0D-4132-BC37-722A0FFB733D} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2261/Swap/Swap/Swap.c" "b/Homework \342\204\2261/Swap/Swap/Swap.c" deleted file mode 100644 index 0807718..0000000 --- "a/Homework \342\204\2261/Swap/Swap/Swap.c" +++ /dev/null @@ -1,15 +0,0 @@ -#include - -int main() -{ - int x, y; - printf("Enter \n"); - scanf_s("%d", &x); - printf("Enter y\n"); - scanf_s("%d", &y); - x = x ^ y; - y = x ^ y; - x = x ^ y; - printf("new value x = %d\n", x); - printf("new value y = %d\n", y); -} \ No newline at end of file diff --git "a/Homework \342\204\2261/Swap/Swap/Swap.vcxproj" "b/Homework \342\204\2261/Swap/Swap/Swap.vcxproj" deleted file mode 100644 index 10993e8..0000000 --- "a/Homework \342\204\2261/Swap/Swap/Swap.vcxproj" +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {9a76efb7-28ee-4317-ad9f-bb16463a313e} - Swap - 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/Homework \342\204\2261/Swap/Swap/Swap.vcxproj.filters" "b/Homework \342\204\2261/Swap/Swap/Swap.vcxproj.filters" deleted file mode 100644 index 4e10e6a..0000000 --- "a/Homework \342\204\2261/Swap/Swap/Swap.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2261/Tickets/Tickets.sln" "b/Homework \342\204\2261/Tickets/Tickets.sln" deleted file mode 100644 index fcb81d8..0000000 --- "a/Homework \342\204\2261/Tickets/Tickets.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "Tickets", "Tickets\Tickets.vcxproj", "{1FB8136F-1E7A-4C30-965B-E162FD9881C1}" -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 - {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Debug|x64.ActiveCfg = Debug|x64 - {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Debug|x64.Build.0 = Debug|x64 - {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Debug|x86.ActiveCfg = Debug|Win32 - {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Debug|x86.Build.0 = Debug|Win32 - {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Release|x64.ActiveCfg = Release|x64 - {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Release|x64.Build.0 = Release|x64 - {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Release|x86.ActiveCfg = Release|Win32 - {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {256FBE0C-5622-4F6D-ACEA-A17FE3CE3039} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2261/Tickets/Tickets/Tickets.c" "b/Homework \342\204\2261/Tickets/Tickets/Tickets.c" deleted file mode 100644 index dbe4642..0000000 --- "a/Homework \342\204\2261/Tickets/Tickets/Tickets.c" +++ /dev/null @@ -1,32 +0,0 @@ -#include - -int main() -{ - int numberSumsDigits[28] = { 0 }; - int totalAmountTickets = 0; - - // use the for loop to find the sums of digits in the first 3-ex positions - for (int i = 0; i < 10; i++) - { - for (int j = 0; j < 10; j++) - { - for (int k = 0; k < 10; k++) - { - - // if the sum of digits i + j + k = n, then the number of sums with the value n is increased by one - ++numberSumsDigits[i + j + k]; - } - } - } - - for (int i = 0; i < 28; i++) - { - /* if there are p tickets on the first 3 positions for the sum i + j + k, the same number of tickets for the sum i + j + k - in the last 3 positions. As a result, for each sum, there are p ^ 2 such tickets */ - numberSumsDigits[i] *= numberSumsDigits[i]; - totalAmountTickets += numberSumsDigits[i]; - } - - printf("number of tickets = %d", totalAmountTickets); - return 0; -} \ No newline at end of file diff --git "a/Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj" "b/Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj" deleted file mode 100644 index 67d93f1..0000000 --- "a/Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj" +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {1fb8136f-1e7a-4c30-965b-e162fd9881c1} - Tickets - 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/Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj.filters" "b/Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj.filters" deleted file mode 100644 index 0cb924d..0000000 --- "a/Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2262/CountAndBubbleSort/CountAndBubbleSort.sln" "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort.sln" deleted file mode 100644 index eac95a3..0000000 --- "a/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "CountAndBubbleSort", "CountAndBubbleSort\CountAndBubbleSort.vcxproj", "{A2AC6B8B-943F-4B6A-8130-896B08DF5092}" -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 - {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Debug|x64.ActiveCfg = Debug|x64 - {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Debug|x64.Build.0 = Debug|x64 - {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Debug|x86.ActiveCfg = Debug|Win32 - {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Debug|x86.Build.0 = Debug|Win32 - {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Release|x64.ActiveCfg = Release|x64 - {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Release|x64.Build.0 = Release|x64 - {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Release|x86.ActiveCfg = Release|Win32 - {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {5235A9BF-195A-49C2-AFDA-DCEF76E17AD0} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.c" "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.c" deleted file mode 100644 index fc0c003..0000000 --- "a/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.c" +++ /dev/null @@ -1,214 +0,0 @@ -#include -#include -#include -#include -#include - -// Function for sorting bubble -void bubbleSortArray(int* arrayOfNumbers, int numberOfElements) -{ - for (int i = 0; i < numberOfElements - 1; i++) - { - for (int j = numberOfElements - 1; j > i; j--) - { - if (arrayOfNumbers[j - 1] > arrayOfNumbers[j]) - { - const int temporary = arrayOfNumbers[j]; - arrayOfNumbers[j] = arrayOfNumbers[j - 1]; - arrayOfNumbers[j - 1] = temporary; - } - } - } -} - -// Function for sorting by counting -int countSortArray(int* arrayOfNumbers, int numberOfElements) -{ - // Finding the minimum element in the array - int minimumElementInArray = arrayOfNumbers[0]; - for (int i = 1; i <= numberOfElements - 1; i++) - { - if (arrayOfNumbers[i] < minimumElementInArray) - { - minimumElementInArray = arrayOfNumbers[i]; - } - } - - // Finding the maximum element in the array - int maximumElementInArray = arrayOfNumbers[0]; - for (int i = 1; i <= numberOfElements - 1; i++) - { - if (arrayOfNumbers[i] > maximumElementInArray) - { - maximumElementInArray = arrayOfNumbers[i]; - } - } - - // Allocation of dynamic memory for a counter array - int* arrayOfCount = (int*)calloc((maximumElementInArray - minimumElementInArray + 1), sizeof(int)); - - if (arrayOfCount == NULL) - { - return -1; - } - // For each element, we increase the counter for its value - for (int i = 0; i <= numberOfElements - 1; i++) - { - arrayOfCount[arrayOfNumbers[i] - minimumElementInArray]++; - } - int distributionounter = 0; - // For each i from the minimum value to the maximum, we write its value to the array sequentially arrayOfCount times - for (int i = minimumElementInArray; i <= maximumElementInArray; i++) - { - for (int j = 0; j < arrayOfCount[i - minimumElementInArray]; j++) - { - arrayOfNumbers[distributionounter] = i; - distributionounter++; - } - } - free(arrayOfCount); - return 0; -} - -bool sortingheck(int* arrayOfNumber, int numberOfElements) -{ - for (int i = 0; i < numberOfElements - 1; i++) - { - if (arrayOfNumber[i] > arrayOfNumber[i + 1]) - { - return false; - } - } - return true; -} - -// Function for testing bubble sorting -bool correctBubbleSort() -{ - // Checking the operation of sorts for a random set of numbers - int arrayOfNumbersForSorting[100] = { 0 }; - for (int i = 0; i < 100; i++) - { - arrayOfNumbersForSorting[i] = rand(); - } - bubbleSortArray(arrayOfNumbersForSorting, 100); - - // Checking the operation of sorts for an array consisting of equal numbers - int arrayOfEqualElements[40] = { 0 }; - for (int i = 0; i < 40; i++) - { - arrayOfEqualElements[i] = 144; - } - bubbleSortArray(arrayOfEqualElements, 40); - - // Checking the operation of sorts for a sorted array - int sortedArray[56] = { 0 }; - for (int i = 0; i < 56; i++) - { - sortedArray[i] = i; - } - bubbleSortArray(sortedArray, 56); - - // Checking the sorting operation for an array consisting of 1 element - int arrayOfOneElement[1] = { 138 }; - bubbleSortArray(arrayOfOneElement, 1); - - // Checking for an array of 0 elements - int arrayOfZeroElement[1] = { 138 }; - bubbleSortArray(arrayOfOneElement, 0); - - return sortingheck(arrayOfNumbersForSorting, 100) == 1 - && sortingheck(arrayOfEqualElements, 40) == 1 - && sortingheck(sortedArray, 56) == 1 - && sortingheck(arrayOfOneElement, 1) == 1 - && sortingheck(arrayOfZeroElement, 0) == 1; - -} - -// Function for testing sorting counting -bool correctCountSort() -{ - // Checking the operation of sorts for a random set of numbers - int arrayOfNumbersForSorting[100] = { 0 }; - for (int i = 0; i < 100; i++) - { - arrayOfNumbersForSorting[i] = rand(); - } - countSortArray(arrayOfNumbersForSorting, 100); - - // Checking the operation of sorts for an array consisting of equal numbers - int arrayOfEqualElements[40] = { 0 }; - for (int i = 0; i < 40; i++) - { - arrayOfEqualElements[i] = 144; - } - countSortArray(arrayOfEqualElements, 40); - - // Checking the operation of sorts for a sorted array - int sortedArray[56] = { 0 }; - for (int i = 0; i < 56; i++) - { - sortedArray[i] = i; - } - countSortArray(sortedArray, 56); - - // Checking the sorting operation for an array consisting of 1 element - int arrayOfOneElement[1] = { 138 }; - countSortArray(arrayOfOneElement, 1); - - // Checking for an array of 0 elements - int arrayOfZeroElement[1] = { 138 }; - countSortArray(arrayOfOneElement, 0); - - return sortingheck(arrayOfNumbersForSorting, 100) - && sortingheck(arrayOfEqualElements, 40) - && sortingheck(sortedArray, 56) - && sortingheck(arrayOfOneElement, 1) - && sortingheck(arrayOfZeroElement, 0); -} - -int main() -{ - if (!correctBubbleSort() || !correctCountSort()) - { - printf("Verification failed"); - return 0; - } - int numberOfElements = 0; - printf("Enter the number of elements in the array\n"); - const int scanfResult = scanf_s("%d", &numberOfElements); - if (scanfResult == 0 || numberOfElements <= 0) - { - printf("Input error"); - return 0; - } - int* arrayOfNumbersForSortingCount = (int*)calloc(numberOfElements, sizeof(int)); - if (arrayOfNumbersForSortingCount == NULL) - { - return -1; - } - - for (int i = 0; i < numberOfElements; i++) - { - arrayOfNumbersForSortingCount[i] = rand(); - } - int* arrayOfNumbersForSortingBubble = (int*)calloc(numberOfElements, sizeof(int)); - if (arrayOfNumbersForSortingBubble == NULL) - { - return -1; - } - for (int i = 0; i < numberOfElements; i++) - { - arrayOfNumbersForSortingBubble[i] = arrayOfNumbersForSortingCount[i]; - } - clock_t initialMomentOfTime = clock(); - countSortArray(arrayOfNumbersForSortingCount, numberOfElements); - clock_t endPointOfTime = clock(); - printf("The number of time cycles that have elapsed since the call of the function that sorts the array by counting = %d \n\n", endPointOfTime - initialMomentOfTime); - initialMomentOfTime = clock(); - bubbleSortArray(arrayOfNumbersForSortingBubble, numberOfElements); - endPointOfTime = clock(); - printf("The number of time cycles that have elapsed since the call of the function that sorts the array with a bubble = %d \n\n", endPointOfTime - initialMomentOfTime); - free(arrayOfNumbersForSortingCount); - free(arrayOfNumbersForSortingBubble); -} \ No newline at end of file diff --git "a/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj" "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj" deleted file mode 100644 index faa09f6..0000000 --- "a/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj" +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {a2ac6b8b-943f-4b6a-8130-896b08df5092} - CountAndBubbleSort - 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/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.filters" "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.filters" deleted file mode 100644 index c57d162..0000000 --- "a/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.user" "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.user" deleted file mode 100644 index 88a5509..0000000 --- "a/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.user" +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git "a/Homework \342\204\2262/Extent/Extent.sln" "b/Homework \342\204\2262/Extent/Extent.sln" deleted file mode 100644 index 5993001..0000000 --- "a/Homework \342\204\2262/Extent/Extent.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "Extent", "Extent\Extent.vcxproj", "{8289129F-61BD-4329-BAAD-1A56B4A73635}" -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 - {8289129F-61BD-4329-BAAD-1A56B4A73635}.Debug|x64.ActiveCfg = Debug|x64 - {8289129F-61BD-4329-BAAD-1A56B4A73635}.Debug|x64.Build.0 = Debug|x64 - {8289129F-61BD-4329-BAAD-1A56B4A73635}.Debug|x86.ActiveCfg = Debug|Win32 - {8289129F-61BD-4329-BAAD-1A56B4A73635}.Debug|x86.Build.0 = Debug|Win32 - {8289129F-61BD-4329-BAAD-1A56B4A73635}.Release|x64.ActiveCfg = Release|x64 - {8289129F-61BD-4329-BAAD-1A56B4A73635}.Release|x64.Build.0 = Release|x64 - {8289129F-61BD-4329-BAAD-1A56B4A73635}.Release|x86.ActiveCfg = Release|Win32 - {8289129F-61BD-4329-BAAD-1A56B4A73635}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {2B6035B2-0A18-43BE-9BF6-6AF14FFDF410} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2262/Extent/Extent/Extent.vcxproj" "b/Homework \342\204\2262/Extent/Extent/Extent.vcxproj" deleted file mode 100644 index b8e014c..0000000 --- "a/Homework \342\204\2262/Extent/Extent/Extent.vcxproj" +++ /dev/null @@ -1,148 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {8289129f-61bd-4329-baad-1a56b4a73635} - Extent - 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 - Default - - - 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\2262/Extent/Extent/Extent.vcxproj.filters" "b/Homework \342\204\2262/Extent/Extent/Extent.vcxproj.filters" deleted file mode 100644 index 7dd0415..0000000 --- "a/Homework \342\204\2262/Extent/Extent/Extent.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2262/Extent/Extent/Extent.vcxproj.user" "b/Homework \342\204\2262/Extent/Extent/Extent.vcxproj.user" deleted file mode 100644 index 88a5509..0000000 --- "a/Homework \342\204\2262/Extent/Extent/Extent.vcxproj.user" +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git "a/Homework \342\204\2262/Extent/Extent/extent.c" "b/Homework \342\204\2262/Extent/Extent/extent.c" deleted file mode 100644 index 7f5b838..0000000 --- "a/Homework \342\204\2262/Extent/Extent/extent.c" +++ /dev/null @@ -1,117 +0,0 @@ -#include -#include -#include - -// function that returns the result depending on the signs of the exponent and the base of the degree (double for degrees of type 5^(-4) = 0.0016). = 0.0016). -double resultFromSign(double exponentiationResult, int basisOfDegree, int degreeIndicator) -{ - if (basisOfDegree > 0 && degreeIndicator < 0) - { - return 1 / exponentiationResult; - } - - if (basisOfDegree > 0 && degreeIndicator > 0) - { - return exponentiationResult; - } - - if (basisOfDegree < 0 && degreeIndicator > 0) - { - if (degreeIndicator % 2 != 0) - { - return -exponentiationResult; - } - - if (degreeIndicator % 2 == 0) - { - return exponentiationResult; - } - } - - if (basisOfDegree < 0 && degreeIndicator < 0) - { - if (degreeIndicator % 2 != 0) - { - return -1 / exponentiationResult; - } - - if (degreeIndicator % 2 == 0) - { - return 1 / exponentiationResult; - } - } - - if (basisOfDegree != 0 && degreeIndicator == 0) - { - return 1; - } - return 0; -} - -// exponentiation in O (log n) -double effectiveExponentiation(int basisOfDegree, int degreeIndicator) -{ - double exponentiationResult = 1; - int absoluteValueDegreeIndicator = abs(degreeIndicator); - double absoluteValueBasisOfDegree = abs(basisOfDegree); - while (absoluteValueDegreeIndicator > 0) - { - if (absoluteValueDegreeIndicator % 2 == 0) - { - absoluteValueDegreeIndicator = absoluteValueDegreeIndicator / 2; - absoluteValueBasisOfDegree *= absoluteValueBasisOfDegree; - } - else - { - absoluteValueDegreeIndicator--; - exponentiationResult *= absoluteValueBasisOfDegree; - } - } - exponentiationResult = resultFromSign(exponentiationResult, basisOfDegree, degreeIndicator); - return exponentiationResult; -} - -// exponentiation in linear time -double ineffectiveExponentiation(int basisOfDegree, int degreeIndicator) -{ - double exponentiationResult = 1; - int absoluteValueDegreeIndicator = abs(degreeIndicator); - int absoluteValueBasisOfDegree = abs(basisOfDegree); - for (int i = 1; i <= absoluteValueDegreeIndicator; i++) - { - exponentiationResult *= absoluteValueBasisOfDegree; - } - exponentiationResult = resultFromSign(exponentiationResult, basisOfDegree, degreeIndicator); - return exponentiationResult; -} - -bool testCorrectExponentiation() -{ - return effectiveExponentiation(-1, 5) == -1 && ineffectiveExponentiation(-1, 5) == -1 - && effectiveExponentiation(0, 5) == 0 && ineffectiveExponentiation(0, 5) == 0 - && effectiveExponentiation(5, 0) == 1 && ineffectiveExponentiation(5, 0) == 1 - && effectiveExponentiation(-5, -2) == 0.04 && effectiveExponentiation(2, -5) == 0.03125 - && ineffectiveExponentiation(12, 4) == 20736 && ineffectiveExponentiation(2, -4) == 0.0625; -} - -int main() -{ - if (!testCorrectExponentiation()) - { - printf("The test failed\n"); - return 0; - } - printf("Enter the degree base\n"); - int basisOfDegree = 0; - scanf_s("%d", &basisOfDegree); - printf("Enter the degree indicator\n"); - int degreeIndicator = 0; - scanf_s("%d", °reeIndicator); - if (basisOfDegree == 0 && degreeIndicator == 0) - { - printf("The expression doesn't make sense."); - return 0; - } - printf("Exponentiation in O (log n) : %.16lf\n\n", effectiveExponentiation(basisOfDegree, degreeIndicator)); - printf("Exponentiation in linear time : %.16lf\n", ineffectiveExponentiation(basisOfDegree, degreeIndicator)); -} \ No newline at end of file diff --git "a/Homework \342\204\2262/Fibonacci/Fibonacci.sln" "b/Homework \342\204\2262/Fibonacci/Fibonacci.sln" deleted file mode 100644 index 1232aa0..0000000 --- "a/Homework \342\204\2262/Fibonacci/Fibonacci.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "Fibonacci", "Fibonacci\Fibonacci.vcxproj", "{462949E2-AB0D-4103-A82A-3277512C135D}" -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 - {462949E2-AB0D-4103-A82A-3277512C135D}.Debug|x64.ActiveCfg = Debug|x64 - {462949E2-AB0D-4103-A82A-3277512C135D}.Debug|x64.Build.0 = Debug|x64 - {462949E2-AB0D-4103-A82A-3277512C135D}.Debug|x86.ActiveCfg = Debug|Win32 - {462949E2-AB0D-4103-A82A-3277512C135D}.Debug|x86.Build.0 = Debug|Win32 - {462949E2-AB0D-4103-A82A-3277512C135D}.Release|x64.ActiveCfg = Release|x64 - {462949E2-AB0D-4103-A82A-3277512C135D}.Release|x64.Build.0 = Release|x64 - {462949E2-AB0D-4103-A82A-3277512C135D}.Release|x86.ActiveCfg = Release|Win32 - {462949E2-AB0D-4103-A82A-3277512C135D}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {74CBB9D0-7E3B-4009-AB0B-5F9EF9CFFA4B} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.c" "b/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.c" deleted file mode 100644 index 655a01d..0000000 --- "a/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.c" +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include - -int sequenceFibonacciIteration(int numberOfSequence) -{ - // checking for the correctness of the entered number - if (numberOfSequence < 0) - { - printf("Input error."); - return -1; - } - - int firstElementSequenceOfFibonacci = 1; - int secondElementSequenceOfFibonacci = 1; - int thirdElementSequenceOfFibonacci = 0; - - for (int i = 0; i < numberOfSequence - 2; i++) - { - thirdElementSequenceOfFibonacci = firstElementSequenceOfFibonacci + secondElementSequenceOfFibonacci; - firstElementSequenceOfFibonacci = secondElementSequenceOfFibonacci; - secondElementSequenceOfFibonacci = thirdElementSequenceOfFibonacci; - } - - if (numberOfSequence == 0) - { - return 0; - } - - if (numberOfSequence > 0) - { - return secondElementSequenceOfFibonacci; - } -} - -int sequenceFibonacciRecursion(int numberOfSequence) -{ - // checking for the correctness of the entered number - if (numberOfSequence < 0) - { - printf("Input error."); - exit(0); - } - - if (numberOfSequence == 1) - { - return 1; - } - - if (numberOfSequence == 0) - { - return 0; - } - - return sequenceFibonacciRecursion(numberOfSequence - 1) + sequenceFibonacciRecursion(numberOfSequence - 2); -} - -// function for checking the correctness of the program -bool testCorrectFibonacci() -{ - return sequenceFibonacciIteration(1) == 1 && sequenceFibonacciRecursion(1) == 1 - && sequenceFibonacciIteration(0) == 0 && sequenceFibonacciRecursion(0) == 0 - && sequenceFibonacciIteration(12) == 144 && sequenceFibonacciRecursion(12) == 144 - && sequenceFibonacciIteration(16) == 987 - && sequenceFibonacciRecursion(20) == 6765; -} - -int main() -{ - if (!testCorrectFibonacci()) - { - printf("Verification failed"); - return 0; - } - printf("Enter the number of the member of the Fibonacci sequence that you want to display on the screen\n"); - int numberOfSequence = 0; - scanf_s("%d", &numberOfSequence); - printf("Iterative version : %d\n", sequenceFibonacciIteration(numberOfSequence)); - printf("Recursive version : %d\n", sequenceFibonacciRecursion(numberOfSequence)); -} \ No newline at end of file diff --git "a/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj" "b/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj" deleted file mode 100644 index 41e4761..0000000 --- "a/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj" +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {462949e2-ab0d-4103-a82a-3277512c135d} - Fibonacci - 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/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.filters" "b/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.filters" deleted file mode 100644 index dd68821..0000000 --- "a/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.user" "b/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.user" deleted file mode 100644 index 88a5509..0000000 --- "a/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.user" +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git "a/Homework \342\204\2262/semiQSort/semiQSort.sln" "b/Homework \342\204\2262/semiQSort/semiQSort.sln" deleted file mode 100644 index de507e6..0000000 --- "a/Homework \342\204\2262/semiQSort/semiQSort.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "semiQSort", "semiQSort\semiQSort.vcxproj", "{504AECC2-9812-4877-A7D8-6D3870ACDA9B}" -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 - {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Debug|x64.ActiveCfg = Debug|x64 - {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Debug|x64.Build.0 = Debug|x64 - {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Debug|x86.ActiveCfg = Debug|Win32 - {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Debug|x86.Build.0 = Debug|Win32 - {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Release|x64.ActiveCfg = Release|x64 - {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Release|x64.Build.0 = Release|x64 - {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Release|x86.ActiveCfg = Release|Win32 - {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {AF819222-5F44-4372-8F2B-E48E71B4478F} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.c" "b/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.c" deleted file mode 100644 index f1fe32f..0000000 --- "a/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.c" +++ /dev/null @@ -1,119 +0,0 @@ -#include -#include -#include -#include - -int semiQSort(int* arrayOfNumber, int numberElementsInArray) -{ - int increment = 1; - int decrement = numberElementsInArray - 1; - - while (increment < decrement) - { - /* the second condition of the loop is not to add increment once again, because the array can already be sorted and in the - case when there are more elements than the reference less than the elements less than the reference increment will increase to countOfElementsLessFirst + 1 and only - after that, the cycle will stop, i.e. a lot of extra increments will be made*/ - while (arrayOfNumber[increment] < arrayOfNumber[0] && increment < decrement) - { - increment++; - } - while (arrayOfNumber[decrement] >= arrayOfNumber[0] && decrement > increment) - { - decrement--; - } - if (increment < decrement) - { - const int temporaryVariable = arrayOfNumber[decrement]; - arrayOfNumber[decrement] = arrayOfNumber[increment]; - arrayOfNumber[increment] = temporaryVariable; - } - increment++; - decrement--; - } - return decrement; -} - -bool sortingheck(int* arrayOfNumber, int numberOfElements, int index) -{ - for (int i = 1; i < index + 1; i++) - { - if (arrayOfNumber[i] >= arrayOfNumber[0]) - { - return false; - } - } - for (int i = index + 1; i < numberOfElements; i++) - { - if (arrayOfNumber[i] < arrayOfNumber[0]) - { - return false; - } - } - return true; -} - -bool correctSemiQSort() -{ - // Checking the operation of sorting for a random set of numbers - int arrayOfNumber[8] = {4, 7, 2, 5, 4, 8, 1, 3}; - - // Checking the sorting operation for an array consisting of equal elements - int arrayOfEqualValues[100] = {0}; - for (int i = 0; i < 100; i++) - { - arrayOfEqualValues[i] = 5; - } - - // Checking the sorting operation for a sorted array - int sortedArray[100] = {0}; - for (int i = 0; i < 100; i++) - { - sortedArray[i] = i; - } - - // Checking the sorting operation for an array consisting of a single element - int arrayOfOneElement[1] = {15}; - - int arrayOfZeroElement[1] = {0}; - - return sortingheck(arrayOfNumber, 8, semiQSort(arrayOfNumber, 8)) - && sortingheck(arrayOfEqualValues, 100, semiQSort(arrayOfEqualValues, 100)) - && sortingheck(sortedArray, 100, semiQSort(sortedArray, 100)) - && sortingheck(arrayOfOneElement, 1, semiQSort(arrayOfOneElement, 1)) - && sortingheck(arrayOfZeroElement, 0, semiQSort(arrayOfZeroElement, 0)); -} - -int main() -{ - if (!correctSemiQSort()) - { - printf("Verification failed"); - return 0; - } - printf("Enter the number of elements in the array\n"); - int numberElementsInArray = 0; - const int scanfNumberElemntInArrayResult = scanf_s("%d", &numberElementsInArray); - if (scanfNumberElemntInArrayResult == 0 || numberElementsInArray <= 0) - { - printf("Input error"); - return 0; - } - int* arrayOfNumber = (int*)calloc(numberElementsInArray, sizeof(int)); - if (arrayOfNumber == NULL) - { - return -1; - } - for (int i = 0; i < numberElementsInArray; i++) - { - // to visually verify that it works correctly, you can add rand () % n, because the first number may be the minimum - arrayOfNumber[i] = rand(); - printf(" %d", arrayOfNumber[i]); - } - printf("\n\n"); - semiQSort(arrayOfNumber, numberElementsInArray); - for (int i = 0; i < numberElementsInArray; i++) - { - printf(" %d", arrayOfNumber[i]); - } - free(arrayOfNumber); -} \ No newline at end of file diff --git "a/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj" "b/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj" deleted file mode 100644 index 4a64740..0000000 --- "a/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj" +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {504aecc2-9812-4877-a7d8-6d3870acda9b} - semiQSort - 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/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.filters" "b/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.filters" deleted file mode 100644 index d6610d1..0000000 --- "a/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2262/semiQSort/semiQSort/semiQSort.vcxproj.user" "b/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.user" deleted file mode 100644 index 88a5509..0000000 --- "a/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.user" +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git "a/Homework \342\204\2263/binarySearch/binarySearch.sln" "b/Homework \342\204\2263/binarySearch/binarySearch.sln" deleted file mode 100644 index 38643b0..0000000 --- "a/Homework \342\204\2263/binarySearch/binarySearch.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "binarySearch", "binarySearch\binarySearch.vcxproj", "{31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}" -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 - {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Debug|x64.ActiveCfg = Debug|x64 - {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Debug|x64.Build.0 = Debug|x64 - {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Debug|x86.ActiveCfg = Debug|Win32 - {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Debug|x86.Build.0 = Debug|Win32 - {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Release|x64.ActiveCfg = Release|x64 - {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Release|x64.Build.0 = Release|x64 - {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Release|x86.ActiveCfg = Release|Win32 - {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {F7D7DBDD-3E67-455A-8DB4-0498CC6E6954} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2263/binarySearch/binarySearch/binary.h" "b/Homework \342\204\2263/binarySearch/binarySearch/binary.h" deleted file mode 100644 index c23afd1..0000000 --- "a/Homework \342\204\2263/binarySearch/binarySearch/binary.h" +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include - -// binary search function -int binarySearch(int* arrayOfNumber, int numberOfElements, int requiredNumber); - -// check if binary search works -bool testCorrectBinarySearch(); diff --git "a/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.c" "b/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.c" deleted file mode 100644 index e181569..0000000 --- "a/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.c" +++ /dev/null @@ -1,61 +0,0 @@ -#include "binary.h" -#include - -// binary search function -int binarySearch(int* arrayOfNumber, int numberOfElements, int requiredNumber) -{ - int leftBorderOfTheArray = 0; - int rightBorderOfTheArray = numberOfElements - 1; - while (leftBorderOfTheArray <= rightBorderOfTheArray) - { - //this form of recording is needed in order to avoid overflow - const int middleElementIndex = leftBorderOfTheArray + (rightBorderOfTheArray - leftBorderOfTheArray) / 2; - if (arrayOfNumber[middleElementIndex] < requiredNumber) - { - leftBorderOfTheArray = middleElementIndex + 1; - } - if (arrayOfNumber[middleElementIndex] > requiredNumber) - { - rightBorderOfTheArray = middleElementIndex - 1; - } - if (arrayOfNumber[middleElementIndex] == requiredNumber) - { - return middleElementIndex; - } - } - return -1; -} - -// check if binary search works -bool testCorrectBinarySearch() -{ - // test for a random set of numbers - int arrayofNumber[10] = { 0, 1, 4, 7, 8, 9, 10, 123, 132, 134 }; - - // test for overflow - int arrayOfLargeNumbers[10] = { 2147483630, 2147483631, 2147483632, 2147483633, 2147483634, 2147483635, 2147483636, 2147483637, 2147483638, 2147483639 }; - - // find the first and last element - int arrayToFindTheFirstAndLastElement[100] = { 0 }; - for (int i = 0; i < 100; i++) - { - arrayToFindTheFirstAndLastElement[i] = i; - } - - // testForEmptyArray - int emptyArray[1] = { 0 }; - - // search for a nonexistent element - int arrayOfRandomNumbers[1000] = { 0 }; - for (int i = 0; i < 1000; i++) - { - arrayOfRandomNumbers[i] = rand() % 226; - } - - return binarySearch(arrayofNumber, 10, 134) == 9 - && binarySearch(arrayOfLargeNumbers, 10, 2147483631) == 1 - && binarySearch(emptyArray, 0, 0) == -1 - && binarySearch(arrayToFindTheFirstAndLastElement, 100, 0) == 0 - && binarySearch(arrayToFindTheFirstAndLastElement, 100, 99) == 99 - && binarySearch(arrayOfRandomNumbers, 1000, 227) == -1; -} \ No newline at end of file diff --git "a/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj" "b/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj" deleted file mode 100644 index 5ed6f94..0000000 --- "a/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj" +++ /dev/null @@ -1,153 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {31d8b8ea-29ab-4f6d-aebb-80d1b64b2a9c} - binarySearch - 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/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj.filters" "b/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj.filters" deleted file mode 100644 index aeaa7ab..0000000 --- "a/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj.filters" +++ /dev/null @@ -1,36 +0,0 @@ - - - - - {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\2263/binarySearch/binarySearch/main.c" "b/Homework \342\204\2263/binarySearch/binarySearch/main.c" deleted file mode 100644 index df065a9..0000000 --- "a/Homework \342\204\2263/binarySearch/binarySearch/main.c" +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include "binary.h" -#include "qsort.h" - -int main() -{ - if (!testCorrectBinarySearch() || !testCorrectQSort()) - { - printf("error"); - return 0; - } - int numberOfElements = 0; - printf("Enter the number of elements in the array\n"); - scanf_s("%d", &numberOfElements); - int* arrayOfNumber = (int*)calloc(numberOfElements, sizeof(int)); - if (arrayOfNumber == NULL) - { - return -1; - } - for (int i = 0; i < numberOfElements; i++) - { - arrayOfNumber[i] = rand(); - } - smartQSort(arrayOfNumber, 0, numberOfElements - 1); - printf("Enter the number of numbers that you need to enter to search in the array\n"); - int numberOfRequiredNumbers = 0; - scanf_s("%d", &numberOfRequiredNumbers); - printf("if (- 1) : then the number is not in the array\n"); - for (int i = 0; i < numberOfRequiredNumbers; i++) - { - const int temporary = rand(); - printf("the number %d : % d array number\n", temporary, binarySearch(arrayOfNumber, numberOfElements, temporary)); - } - free(arrayOfNumber); -} \ No newline at end of file diff --git "a/Homework \342\204\2263/binarySearch/binarySearch/qsort.c" "b/Homework \342\204\2263/binarySearch/binarySearch/qsort.c" deleted file mode 100644 index 530c255..0000000 --- "a/Homework \342\204\2263/binarySearch/binarySearch/qsort.c" +++ /dev/null @@ -1,107 +0,0 @@ -#include "qsort.h" - -// function for sorting by inserts -void sortByInserts(int* arrayOfNumber, int initialElement, int endElement) -{ - for (int i = initialElement + 1; i <= endElement; i++) - { - int elementToTheLeftOfKey = i - 1; - const int keyArray = arrayOfNumber[i]; - while (arrayOfNumber[elementToTheLeftOfKey] > keyArray && elementToTheLeftOfKey >= initialElement) - { - arrayOfNumber[elementToTheLeftOfKey + 1] = arrayOfNumber[elementToTheLeftOfKey]; - elementToTheLeftOfKey--; - } - arrayOfNumber[elementToTheLeftOfKey + 1] = keyArray; - } -} - -// function for sorting an array -void smartQSort(int* arrayOfNumber, int initialElement, int endElement) -{ - int leftBorderOfSegment = initialElement; - int rightBorderOfSegment = endElement; - int supportElement = 0; - if (arrayOfNumber[leftBorderOfSegment] <= arrayOfNumber[leftBorderOfSegment + 1]) - { - supportElement = arrayOfNumber[leftBorderOfSegment + 1]; - } - else - { - supportElement = arrayOfNumber[leftBorderOfSegment]; - } - if (endElement - initialElement + 1 >= 10) - { - while (leftBorderOfSegment < rightBorderOfSegment) - { - while (arrayOfNumber[leftBorderOfSegment] < supportElement && leftBorderOfSegment <= rightBorderOfSegment) - { - leftBorderOfSegment++; - } - while (arrayOfNumber[rightBorderOfSegment] > supportElement && rightBorderOfSegment >= leftBorderOfSegment) - { - rightBorderOfSegment--; - } - if (leftBorderOfSegment < rightBorderOfSegment) - { - const int temporaryVariable = arrayOfNumber[rightBorderOfSegment]; - arrayOfNumber[rightBorderOfSegment] = arrayOfNumber[leftBorderOfSegment]; - arrayOfNumber[leftBorderOfSegment] = temporaryVariable; - leftBorderOfSegment++; - rightBorderOfSegment--; - } - } - smartQSort(arrayOfNumber, initialElement, rightBorderOfSegment); - smartQSort(arrayOfNumber, leftBorderOfSegment, endElement); - } - else - { - sortByInserts(arrayOfNumber, initialElement, endElement); - } -} - -// function for checking the sorting of an array -bool sortingCheck(int* arrayOfNumber, int numberOfElements) -{ - for (int i = 0; i < numberOfElements - 1; i++) - { - if (arrayOfNumber[i] > arrayOfNumber[i + 1]) - { - return false; - } - } - return true; -} - -// function for testing sorting QSort -bool testCorrectQSort() -{ - // Array of random numbers - int arrayOfNumber[10] = { 9, 7, 8, 6, 3, 1, 7, 0, 3, 2 }; - smartQSort(arrayOfNumber, 0, 9); - - // Array of equal numbers - int arrayOfEqualValues[100] = { 0 }; - for (int i = 0; i < 100; i++) - { - arrayOfEqualValues[i] = 12; - } - smartQSort(arrayOfEqualValues, 0, 99); - - // Sorted array - int sortedArray[100] = { 0 }; - for (int i = 0; i < 100; i++) - { - sortedArray[i] = i; - } - smartQSort(sortedArray, 0, 99); - - // Array of one element - int arrayOfOneElement[1] = { 109 }; - smartQSort(arrayOfEqualValues, 0, 0); - - return sortingCheck(arrayOfNumber, 10) - && sortingCheck(arrayOfEqualValues, 100) - && sortingCheck(sortedArray, 100) - && sortingCheck(arrayOfOneElement, 1); -} \ No newline at end of file diff --git "a/Homework \342\204\2263/binarySearch/binarySearch/qsort.h" "b/Homework \342\204\2263/binarySearch/binarySearch/qsort.h" deleted file mode 100644 index 28a2257..0000000 --- "a/Homework \342\204\2263/binarySearch/binarySearch/qsort.h" +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include - -// function for sorting an array -void smartQSort(int* arrayOfNumber, int initialElement, int endElement); - -// function for checking the sorting of an array -bool sortingCheck(int* arrayOfNumber, int numberOfElements); - -// function for testing sorting QSort -bool testCorrectQSort(); - -// function for sorting by inserts -void sortByInserts(int* arrayOfNumber, int initialElement, int endElement); - diff --git "a/Homework \342\204\2263/quickSort/quickSort.sln" "b/Homework \342\204\2263/quickSort/quickSort.sln" deleted file mode 100644 index 8e712d4..0000000 --- "a/Homework \342\204\2263/quickSort/quickSort.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "quickSort", "quickSort\quickSort.vcxproj", "{16F21A94-4C1F-497E-9830-A36A16AC1481}" -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 - {16F21A94-4C1F-497E-9830-A36A16AC1481}.Debug|x64.ActiveCfg = Debug|x64 - {16F21A94-4C1F-497E-9830-A36A16AC1481}.Debug|x64.Build.0 = Debug|x64 - {16F21A94-4C1F-497E-9830-A36A16AC1481}.Debug|x86.ActiveCfg = Debug|Win32 - {16F21A94-4C1F-497E-9830-A36A16AC1481}.Debug|x86.Build.0 = Debug|Win32 - {16F21A94-4C1F-497E-9830-A36A16AC1481}.Release|x64.ActiveCfg = Release|x64 - {16F21A94-4C1F-497E-9830-A36A16AC1481}.Release|x64.Build.0 = Release|x64 - {16F21A94-4C1F-497E-9830-A36A16AC1481}.Release|x86.ActiveCfg = Release|Win32 - {16F21A94-4C1F-497E-9830-A36A16AC1481}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {C1AE2CF6-53F4-44C0-B515-54C3158A1CAE} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj" "b/Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj" deleted file mode 100644 index e3a55d1..0000000 --- "a/Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj" +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {16f21a94-4c1f-497e-9830-a36a16ac1481} - quickSort - 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/Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj.filters" "b/Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj.filters" deleted file mode 100644 index 8b192d6..0000000 --- "a/Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj.filters" +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {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\2263/quickSort/quickSort/quicksort.c" "b/Homework \342\204\2263/quickSort/quickSort/quicksort.c" deleted file mode 100644 index d9dafb9..0000000 --- "a/Homework \342\204\2263/quickSort/quickSort/quicksort.c" +++ /dev/null @@ -1,136 +0,0 @@ -#include -#include -#include -#include - -void sortByInserts(int* arrayOfNumber, int initialElement, int endElement) -{ - for (int i = initialElement + 1; i <= endElement; i++) - { - int elementToTheLeftOfKey = i - 1; - const int keyArray = arrayOfNumber[i]; - while (arrayOfNumber[elementToTheLeftOfKey] > keyArray && elementToTheLeftOfKey >= initialElement) - { - arrayOfNumber[elementToTheLeftOfKey + 1] = arrayOfNumber[elementToTheLeftOfKey]; - elementToTheLeftOfKey--; - } - arrayOfNumber[elementToTheLeftOfKey + 1] = keyArray; - } -} - -void smartQSort(int* arrayOfNumber, int initialElement, int endElement) -{ - int leftBorderOfSegment = initialElement; - int rightBorderOfSegment = endElement; - int supportElement = 0; - if (arrayOfNumber[leftBorderOfSegment] <= arrayOfNumber[leftBorderOfSegment + 1]) - { - supportElement = arrayOfNumber[leftBorderOfSegment + 1]; - } - else - { - supportElement = arrayOfNumber[leftBorderOfSegment]; - } - if (endElement - initialElement + 1 >= 10) - { - while (leftBorderOfSegment < rightBorderOfSegment) - { - while (arrayOfNumber[leftBorderOfSegment] < supportElement && leftBorderOfSegment <= rightBorderOfSegment) - { - leftBorderOfSegment++; - } - while (arrayOfNumber[rightBorderOfSegment] > supportElement && rightBorderOfSegment >= leftBorderOfSegment) - { - rightBorderOfSegment--; - } - if (leftBorderOfSegment < rightBorderOfSegment) - { - const int temporaryVariable = arrayOfNumber[rightBorderOfSegment]; - arrayOfNumber[rightBorderOfSegment] = arrayOfNumber[leftBorderOfSegment]; - arrayOfNumber[leftBorderOfSegment] = temporaryVariable; - leftBorderOfSegment++; - rightBorderOfSegment--; - } - } - smartQSort(arrayOfNumber, initialElement, rightBorderOfSegment); - smartQSort(arrayOfNumber, leftBorderOfSegment, endElement); - } - else - { - sortByInserts(arrayOfNumber, initialElement, endElement); - } -} - -// Function for checking the sorting of an array -bool sortingCheck(int* arrayOfNumber, int numberOfElements) -{ - for (int i = 0; i < numberOfElements - 1; i++) - { - if (arrayOfNumber[i] > arrayOfNumber[i + 1]) - { - return false; - } - } - return true; -} - -// Function for testing QSort sorting -bool testCorrectQSort() -{ - // An array of random numbers - int arrayOfNumber[10] = { 9, 7, 8, 6, 3, 1, 7, 0, 3, 2 }; - smartQSort(arrayOfNumber, 0, 9); - - // An array of equal numbers - int arrayOfEqualValues[100] = { 0 }; - for (int i = 0; i < 100; i++) - { - arrayOfEqualValues[i] = 12; - } - smartQSort(arrayOfEqualValues, 0, 99); - - // Sorted array - int sortedArray[100] = { 0 }; - for (int i = 0; i < 100; i++) - { - sortedArray[i] = i; - } - smartQSort(sortedArray, 0, 99); - - // An array of one element - int arrayOfOneElement[1] = { 109 }; - smartQSort(arrayOfEqualValues, 0, 0); - - return sortingCheck(arrayOfNumber, 10) - && sortingCheck(arrayOfEqualValues, 100) - && sortingCheck(sortedArray, 100) - && sortingCheck(arrayOfOneElement, 1); -} - -int main() -{ - if (!testCorrectQSort()) - { - printf(" error"); - return 0; - } - int numberOfElements = 0; - printf("Enter the number of elements in the array\n"); - scanf_s("%d", &numberOfElements); - int* arrayOfNumber = (int*)calloc(numberOfElements, sizeof(int)); - if (arrayOfNumber == NULL) - { - return -1; - } - // % 14 for clear output to the screen - for (int i = 0; i < numberOfElements; i++) - { - arrayOfNumber[i] = rand() % 14; - } - smartQSort(arrayOfNumber, 0, numberOfElements - 1); - for (int i = 0; i < numberOfElements; i++) - { - printf(" %d", arrayOfNumber[i]); - } - free(arrayOfNumber); -} \ No newline at end of file diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement.sln" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement.sln" deleted file mode 100644 index a4e9d28..0000000 --- "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "theMostCommonElement", "theMostCommonElement\theMostCommonElement.vcxproj", "{EF7D2016-E0AC-4058-B9D6-C845C565D6BB}" -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 - {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Debug|x64.ActiveCfg = Debug|x64 - {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Debug|x64.Build.0 = Debug|x64 - {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Debug|x86.ActiveCfg = Debug|Win32 - {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Debug|x86.Build.0 = Debug|Win32 - {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Release|x64.ActiveCfg = Release|x64 - {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Release|x64.Build.0 = Release|x64 - {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Release|x86.ActiveCfg = Release|Win32 - {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {4CDB3EC5-EBAA-41F9-A341-71F57200891A} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.c" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.c" deleted file mode 100644 index c9b8be2..0000000 --- "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.c" +++ /dev/null @@ -1,33 +0,0 @@ -#include "TheMostCommonElement.h" - -// function to find the most frequent element in an array -int searchMostCommonElementInArray(int* arrayOfNumber, int numberOfElements) -{ - int currentElement = arrayOfNumber[0]; - int counterTheCurrentElement = 1; - int counterThePreviousElement = 1; - int savingTheCurrentElement = currentElement; - for (int i = 1; i < numberOfElements; i++) - { - if (arrayOfNumber[i] == currentElement) - { - counterTheCurrentElement++; - } - else - { - if (counterTheCurrentElement > counterThePreviousElement) - { - counterThePreviousElement = counterTheCurrentElement; - savingTheCurrentElement = currentElement; - } - currentElement = arrayOfNumber[i]; - counterTheCurrentElement = 1; - } - } - // condition for the last element (if the last element was repeated, then else from the for loop will not work for it) - if (counterThePreviousElement < counterTheCurrentElement) - { - savingTheCurrentElement = currentElement; - } - return savingTheCurrentElement; -} \ No newline at end of file diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.h" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.h" deleted file mode 100644 index 14b066b..0000000 --- "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.h" +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -// function to find the most frequent element in an array -int searchMostCommonElementInArray(int* arrayOfNumber, int numberOfElements); \ No newline at end of file diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/main.c" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/main.c" deleted file mode 100644 index 2210d3f..0000000 --- "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/main.c" +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include "theMostCommonElement.h" -#include "qsort.h" -#include "test.h" - -int main() -{ - if (!testCorrectQSort() || !testSearchMostCommonElement()) - { - printf("test failed"); - return -1; - } - int numberOfElements = 0; - printf("enter the number of elements in the array\n"); - scanf_s("%d", &numberOfElements); - int* arrayOfNumber = (int*)calloc(numberOfElements, sizeof(int)); - if (arrayOfNumber == NULL) - { - return -1; - } - for (int i = 0; i < numberOfElements; i++) - { - arrayOfNumber[i] = rand() % 11; - } - QSort(arrayOfNumber, numberOfElements); - printf("the most common element in the array : %d\n", searchMostCommonElementInArray(arrayOfNumber, numberOfElements)); -} \ No newline at end of file diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.c" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.c" deleted file mode 100644 index ba7cbfc..0000000 --- "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.c" +++ /dev/null @@ -1,64 +0,0 @@ -#include "qsort.h" - -void QSort(int* arrayOfNumber, int numberOfElement) -{ - smartQSort(arrayOfNumber, 0, numberOfElement - 1); -} -// function for sorting by inserts -void sortByInserts(int* arrayOfNumber, int initialElement, int endElement) -{ - for (int i = initialElement + 1; i <= endElement; i++) - { - int elementToTheLeftOfKey = i - 1; - const int keyArray = arrayOfNumber[i]; - while (arrayOfNumber[elementToTheLeftOfKey] > keyArray && elementToTheLeftOfKey >= initialElement) - { - arrayOfNumber[elementToTheLeftOfKey + 1] = arrayOfNumber[elementToTheLeftOfKey]; - elementToTheLeftOfKey--; - } - arrayOfNumber[elementToTheLeftOfKey + 1] = keyArray; - } -} - -// function for sorting an array -int smartQSort(int* arrayOfNumber, int initialElement, int endElement) -{ - if (endElement - initialElement + 1 < 10) - { - sortByInserts(arrayOfNumber, initialElement, endElement); - return 0; - } - int leftBorderOfSegment = initialElement; - int rightBorderOfSegment = endElement; - int supportElement = 0; - if (arrayOfNumber[leftBorderOfSegment] <= arrayOfNumber[leftBorderOfSegment + 1]) - { - supportElement = arrayOfNumber[leftBorderOfSegment + 1]; - } - else - { - supportElement = arrayOfNumber[leftBorderOfSegment]; - } - while (leftBorderOfSegment < rightBorderOfSegment) - { - while (arrayOfNumber[leftBorderOfSegment] < supportElement && leftBorderOfSegment <= rightBorderOfSegment) - { - leftBorderOfSegment++; - } - while (arrayOfNumber[rightBorderOfSegment] > supportElement && rightBorderOfSegment >= leftBorderOfSegment) - { - rightBorderOfSegment--; - } - if (leftBorderOfSegment < rightBorderOfSegment) - { - const int temporaryVariable = arrayOfNumber[rightBorderOfSegment]; - arrayOfNumber[rightBorderOfSegment] = arrayOfNumber[leftBorderOfSegment]; - arrayOfNumber[leftBorderOfSegment] = temporaryVariable; - leftBorderOfSegment++; - rightBorderOfSegment--; - } - } - smartQSort(arrayOfNumber, initialElement, rightBorderOfSegment); - smartQSort(arrayOfNumber, leftBorderOfSegment, endElement); - return 0; -} \ No newline at end of file diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.h" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.h" deleted file mode 100644 index 32bf1ac..0000000 --- "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.h" +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -// function for sorting an array -void QSort(int* arrayOfNumber, int numberOfElements); diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/test.h" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/test.h" deleted file mode 100644 index 06fcb19..0000000 --- "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/test.h" +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include - -// function for testing sorting QSort -bool testCorrectQSort(); - -// test for function searchMostCommonElementInArray -bool testSearchMostCommonElement(); diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/tests.c" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/tests.c" deleted file mode 100644 index 5a14692..0000000 --- "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/tests.c" +++ /dev/null @@ -1,70 +0,0 @@ -#include "test.h" -#include "qsort.h" -#include "theMostCommonElement.h" - -// function for checking the sorting of an array -bool sortingCheck(int* arrayOfNumber, int numberOfElements) -{ - for (int i = 0; i < numberOfElements - 1; i++) - { - if (arrayOfNumber[i] > arrayOfNumber[i + 1]) - { - return false; - } - } - return true; -} - -// function for testing sorting QSort -bool testCorrectQSort() -{ - // Array of random numbers - int arrayOfNumber[10] = { 9, 7, 8, 6, 3, 1, 7, 0, 3, 2 }; - QSort(arrayOfNumber, 10); - - // Array of equal numbers - int arrayOfEqualValues[100] = { 0 }; - for (int i = 0; i < 100; i++) - { - arrayOfEqualValues[i] = 12; - } - QSort(arrayOfEqualValues, 100); - - // Sorted array - int sortedArray[100] = { 0 }; - for (int i = 0; i < 100; i++) - { - sortedArray[i] = i; - } - QSort(sortedArray, 100); - - // Array of one element - int arrayOfOneElement[1] = { 109 }; - QSort(arrayOfEqualValues, 1); - - return sortingCheck(arrayOfNumber, 10) - && sortingCheck(arrayOfEqualValues, 100) - && sortingCheck(sortedArray, 100) - && sortingCheck(arrayOfOneElement, 1); -} - -// test for function searchMostCommonElementInArray -bool testSearchMostCommonElement() -{ - // Checking for a random set of numbers - int arrayOfRandonNumbers[15] = { 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 6, 8, 9, 12, 13 }; - - // checking for an array of a single number - int arrayOfOneElement[1] = { 12 }; - - // checking for an array of equal number - int arrayOfEqualNumbers[8] = { 1, 1, 1, 1, 1, 1, 1, 1 }; - - // check for an array of different number - int arrayOfDifferentNumbers[15] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; - - return searchMostCommonElementInArray(arrayOfRandonNumbers, 15) == 3 - && searchMostCommonElementInArray(arrayOfOneElement, 1) == 12 - && searchMostCommonElementInArray(arrayOfEqualNumbers, 8) == 1 - && searchMostCommonElementInArray(arrayOfDifferentNumbers, 15) == 1; -} \ No newline at end of file diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj" deleted file mode 100644 index d621f34..0000000 --- "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj" +++ /dev/null @@ -1,155 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {ef7d2016-e0ac-4058-b9d6-c845c565d6bb} - theMostCommonElement - 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/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj.filters" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj.filters" deleted file mode 100644 index e6a7184..0000000 --- "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj.filters" +++ /dev/null @@ -1,42 +0,0 @@ - - - - - {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\2264/Phonebook/Phonebook.sln" "b/Homework \342\204\2264/Phonebook/Phonebook.sln" deleted file mode 100644 index 1f924d5..0000000 --- "a/Homework \342\204\2264/Phonebook/Phonebook.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "Phonebook", "Phonebook\Phonebook.vcxproj", "{65870562-A022-4E69-83E5-D43FD4B796E2}" -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 - {65870562-A022-4E69-83E5-D43FD4B796E2}.Debug|x64.ActiveCfg = Debug|x64 - {65870562-A022-4E69-83E5-D43FD4B796E2}.Debug|x64.Build.0 = Debug|x64 - {65870562-A022-4E69-83E5-D43FD4B796E2}.Debug|x86.ActiveCfg = Debug|Win32 - {65870562-A022-4E69-83E5-D43FD4B796E2}.Debug|x86.Build.0 = Debug|Win32 - {65870562-A022-4E69-83E5-D43FD4B796E2}.Release|x64.ActiveCfg = Release|x64 - {65870562-A022-4E69-83E5-D43FD4B796E2}.Release|x64.Build.0 = Release|x64 - {65870562-A022-4E69-83E5-D43FD4B796E2}.Release|x86.ActiveCfg = Release|Win32 - {65870562-A022-4E69-83E5-D43FD4B796E2}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {F6FADCAE-DF15-48D7-B221-EFC0510BD591} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj" "b/Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj" deleted file mode 100644 index 58566a5..0000000 --- "a/Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj" +++ /dev/null @@ -1,153 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {65870562-a022-4e69-83e5-d43fd4b796e2} - Phonebook - 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\2264/Phonebook/Phonebook/Phonebook.vcxproj.filters" "b/Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj.filters" deleted file mode 100644 index 8d00e84..0000000 --- "a/Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj.filters" +++ /dev/null @@ -1,36 +0,0 @@ - - - - - {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\2264/Phonebook/Phonebook/main.c" "b/Homework \342\204\2264/Phonebook/Phonebook/main.c" deleted file mode 100644 index c63f313..0000000 --- "a/Homework \342\204\2264/Phonebook/Phonebook/main.c" +++ /dev/null @@ -1,128 +0,0 @@ -#include "phoneBook.h" -#include "tests.h" -#include -#include - -int main() -{ - setlocale(LC_ALL, "rus"); - if (!testFunctionsWorkingWithFile()) - { - printf(" "); - return -1; - } - setlocale(LC_ALL, "rus"); - printf("0 - \n"); - printf("1 - ( )\n"); - printf("2 - \n"); - printf("3 - \n"); - printf("4 - \n"); - printf("5 - \n"); - Phonebook array[100] = {0}; - int number = 1; - int numberOfRecords = readPhonebook(array, "phoneNumber.txt"); - while (number != 0) - { - printf(" ?\n"); - while (scanf("%d", &number) == 0) - { - printf(", 0 5\n"); - while (getchar() != '\n') - { - continue; - } - } - switch (number) - { - case 0: - { - return 0; - } - case 1: - { - printf(" \n"); - char name[20] = {'\0'}; - if (scanf("%s", name) == 0) - { - printf(" \n"); - break; - } - printf(" \n"); - char phoneNumber[20] = {'\0'}; - if (scanf("%s", phoneNumber) == 0) - { - printf(" \n"); - break; - } - const int addAnEntryResult = addAnEntry(array, &numberOfRecords, name, phoneNumber); - if (addAnEntryResult == -1) - { - printf(" : 100 "); - } - break; - } - case 2: - { - outputAllEntries(array, numberOfRecords); - break; - } - case 3: - { - char name[20] = {'\0'}; - printf(" \n"); - if (scanf("%s", name) == 0) - { - printf(" \n"); - break; - } - const char* findNumberByNameResult = findNumberByName(array, name, numberOfRecords); - if (findNumberByNameResult == NULL) - { - printf(" \n"); - } - else - { - printf("%s\n", findNumberByNameResult); - } - break; - } - case 4: - { - char phoneNumber[20] = { '\0' }; - printf(" \n"); - if (scanf("%s", phoneNumber) == 0) - { - printf(" \n"); - break; - } - const char *findNameByNumberResult = findNameByNumber(array, phoneNumber, numberOfRecords); - if (findNameByNumberResult == NULL) - { - printf(" \n"); - } - else - { - printf("%s\n", findNameByNumberResult); - } - break; - } - case 5: - { - if (saveTheChanges(array, numberOfRecords) == 0) - { - printf("\n"); - } - else - { - printf(" \n"); - } - break; - } - default: - { - printf(", 0 5\n"); - break; - } - } - } -} diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/phoneBook.c" "b/Homework \342\204\2264/Phonebook/Phonebook/phoneBook.c" deleted file mode 100644 index 116d6ba..0000000 --- "a/Homework \342\204\2264/Phonebook/Phonebook/phoneBook.c" +++ /dev/null @@ -1,90 +0,0 @@ -#include "phoneBook.h" -#include -#include - -int readPhonebook(Phonebook* array, const char *fileName) -{ - FILE* file = fopen(fileName, "r"); - if (file == NULL) - { - return -1; - } - int numberOfRecords = 0; - while (!feof(file)) - { - if (fscanf(file, "%s", array[numberOfRecords].name) != EOF); - { - const int fscanfResult = fscanf(file, "%s", &array[numberOfRecords].number); - if (fscanfResult == 0) - { - break; - } - numberOfRecords++; - } - } - fclose(file); - return numberOfRecords - 1; -} - -int addAnEntry(Phonebook* array, int* numberOfRecords, const char* name, const char* phoneNumber) -{ - if (*numberOfRecords >= 100) - { - return -1; - } - (*numberOfRecords)++; - strncpy(array[*numberOfRecords].name, name, 20); - strncpy(array[*numberOfRecords].number, phoneNumber, 20); - return 1; -} - -char* findNameByNumber(Phonebook* array, const char* number, int numberOfRecords) -{ - for (int i = 0; i <= numberOfRecords; i++) - { - if (strcmp(array[i].number, number) == 0) - { - return array[i].name; - } - } - return NULL; -} - -int saveTheChanges(Phonebook* array, int numberOfRecords) -{ - FILE* file = fopen("phoneNumber.txt", "w"); - if (file == NULL) - { - return -1; - } - for (int i = 0; i <= numberOfRecords; i++) - { - if (i > 0) - { - fprintf(file, "\n"); - } - fprintf(file, "%s %s", array[i].name, array[i].number); - } - fclose(file); - return 0; -} - -char* findNumberByName(Phonebook* array, const char* name, int numberOfRecords) -{ - for (int i = 0; i <= numberOfRecords; i++) - { - if (strcmp(array[i].name, name) == 0) - { - return array[i].number; - } - } - return NULL; -} - -void outputAllEntries(Phonebook* array, int numberOfRecords) -{ - for (int i = 0; i <= numberOfRecords; i++) - { - printf("%s %s\n", array[i].name, array[i].number); - } -} diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/phoneBook.h" "b/Homework \342\204\2264/Phonebook/Phonebook/phoneBook.h" deleted file mode 100644 index 6213c96..0000000 --- "a/Homework \342\204\2264/Phonebook/Phonebook/phoneBook.h" +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -// Phonebook structure for storing names and phone numbers -typedef struct -{ - char number[20]; - char name[20]; -} Phonebook; - -// Function for adding an entry to the database of numbers -int addAnEntry(Phonebook* array, int* numberOfRecords, const char* name, const char* phoneNumber); - -// Function for finding a name by phone number -char* findNameByNumber(Phonebook* array, const char* number, int numberOfRecords); - -// Function for finding a phone number by name -char* findNumberByName(Phonebook* array, const char* name, int numberOfRecords); - -// Function for displaying records on the screen -void outputAllEntries(Phonebook* array, int numberOfRecords); - -// Function for filling the phone book returns the number of entries minus one(since the count starts from 0) -int readPhonebook(Phonebook* array, const char* fileName); - -// Function for saving changes -int saveTheChanges(Phonebook* array, int numberOfRecords); - diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/phoneNumber.txt" "b/Homework \342\204\2264/Phonebook/Phonebook/phoneNumber.txt" deleted file mode 100644 index c272978..0000000 --- "a/Homework \342\204\2264/Phonebook/Phonebook/phoneNumber.txt" +++ /dev/null @@ -1,19 +0,0 @@ -Ivan 89624561234 -Athanasius 234456748 -Georgy 675482949 -Alexander 3645783 -Mahmed 98456232 -Murat 12845637 -Artem 35809124 -Peter 134754843 -Matway 9045673737 -Boris 89623457 -Nikolay 234567 -Oleg 5678904 -Roman 890754345 -Pavel 4567890 -Andrey 56789000 -Nikita 44567890 -Maxim 12312312 -Anna 23453123 -Olga 12365568 \ No newline at end of file diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/test1.txt" "b/Homework \342\204\2264/Phonebook/Phonebook/test1.txt" deleted file mode 100644 index f6f117a..0000000 --- "a/Homework \342\204\2264/Phonebook/Phonebook/test1.txt" +++ /dev/null @@ -1,4 +0,0 @@ -Alex 5642345 -John 5432356 -James 90812345 -Qwerty 896751 \ No newline at end of file diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/tests.c" "b/Homework \342\204\2264/Phonebook/Phonebook/tests.c" deleted file mode 100644 index 4fa77fe..0000000 --- "a/Homework \342\204\2264/Phonebook/Phonebook/tests.c" +++ /dev/null @@ -1,34 +0,0 @@ -#include "tests.h" -#include "phoneBook.h" -#include -#include - -bool testFunctionsWorkingWithFile() -{ - Phonebook arrayForTest[4] = {'\0'}; - FILE* file = fopen("test1.txt", "r"); - if (file == NULL) - { - return -1; - } - for (int i = 0; i < 4; i++) - { - if (fscanf(file, "%s", arrayForTest[i].name) != EOF); - { - const int fscanfResult = fscanf(file, "%s", &arrayForTest[i].number); - if (fscanfResult == 0) - { - break; - } - } - } - fclose(file); - - return strcmp("Alex", findNameByNumber(arrayForTest, "5642345", 4)) == 0 - && strcmp("John", findNameByNumber(arrayForTest, "5432356", 4)) == 0 - && strcmp("James", findNameByNumber(arrayForTest, "90812345", 4)) == 0 - && strcmp("5642345", findNumberByName(arrayForTest, "Alex", 4)) == 0 - && strcmp("5432356", findNumberByName(arrayForTest, "John", 4)) == 0 - && strcmp("90812345", findNumberByName(arrayForTest, "James", 4)) == 0 - && readPhonebook(arrayForTest, "test1.txt") == 3; -} diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/tests.h" "b/Homework \342\204\2264/Phonebook/Phonebook/tests.h" deleted file mode 100644 index 46df35a..0000000 --- "a/Homework \342\204\2264/Phonebook/Phonebook/tests.h" +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once -#include - -// Function for testing a function that finds a name by phone number -bool testFunctionsWorkingWithFile(); diff --git "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers.sln" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers.sln" deleted file mode 100644 index b49f86d..0000000 --- "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers.sln" +++ /dev/null @@ -1,31 +0,0 @@ - -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}") = "additionOfNumbers", "additionOfNumbers\additionOfNumbers.vcxproj", "{A08BCEED-1B88-4D26-B359-79E74996FB01}" -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 - {A08BCEED-1B88-4D26-B359-79E74996FB01}.Debug|x64.ActiveCfg = Debug|x64 - {A08BCEED-1B88-4D26-B359-79E74996FB01}.Debug|x64.Build.0 = Debug|x64 - {A08BCEED-1B88-4D26-B359-79E74996FB01}.Debug|x86.ActiveCfg = Debug|Win32 - {A08BCEED-1B88-4D26-B359-79E74996FB01}.Debug|x86.Build.0 = Debug|Win32 - {A08BCEED-1B88-4D26-B359-79E74996FB01}.Release|x64.ActiveCfg = Release|x64 - {A08BCEED-1B88-4D26-B359-79E74996FB01}.Release|x64.Build.0 = Release|x64 - {A08BCEED-1B88-4D26-B359-79E74996FB01}.Release|x86.ActiveCfg = Release|Win32 - {A08BCEED-1B88-4D26-B359-79E74996FB01}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {2E10007C-0307-4D02-8E34-DFE498F5CDC2} - EndGlobalSection -EndGlobal diff --git "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj" deleted file mode 100644 index 9ecf018..0000000 --- "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj" +++ /dev/null @@ -1,153 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {a08bceed-1b88-4d26-b359-79e74996fb01} - additionOfNumbers - 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/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj.filters" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj.filters" deleted file mode 100644 index 9f5be3f..0000000 --- "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj.filters" +++ /dev/null @@ -1,36 +0,0 @@ - - - - - {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\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.c" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.c" deleted file mode 100644 index d790566..0000000 --- "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.c" +++ /dev/null @@ -1,49 +0,0 @@ -#include "binaryNumberSystem.h" -#include - -void writeDigitsToArray(int* arrayOfNumber, int numberToWrite) -{ - for (int j = 0; j < sizeof(int) * 8; ++j) - { - arrayOfNumber[j] = ((numberToWrite & 1) ? 1 : 0); - numberToWrite >>= 1; - } -} - -void outputtingNumberInBinaryNotation(int* arrayOfNumber) -{ - for (int j = sizeof(int) * 8 - 1; j >= 0; --j) - { - printf("%d", arrayOfNumber[j]); - } -} - -void additionOfDigitsOfTwoNumbers(int* arrayOfDigitsOfTheFirstNumber, int* arrayOfDigitsOfTheSecondNumber,int* arrayForWritingTheSumOfDigits) -{ - int remainder = 0; - for (int j = 0; j < sizeof(int) * 8; ++j) - { - if (j > 0 && arrayOfDigitsOfTheFirstNumber[j - 1] + arrayOfDigitsOfTheSecondNumber[j - 1] - + remainder == 2 || j > 0 && arrayOfDigitsOfTheFirstNumber[j - 1] + arrayOfDigitsOfTheSecondNumber[j - 1] + remainder == 3) - { - remainder = 1; - } - else - { - remainder = 0; - } - arrayForWritingTheSumOfDigits[j] = (arrayOfDigitsOfTheFirstNumber[j] + arrayOfDigitsOfTheSecondNumber[j] + remainder) % 2; - } -} - -int convertNumberFromBinaryToDecimal(int* arrayForWritingTheSumOfDigits) -{ - int decimalNumber = 0; - int positionMagnifier = 1; - for (int j = 0; j <= sizeof(int) * 8 - 1; j++) - { - decimalNumber = decimalNumber | (arrayForWritingTheSumOfDigits[j] == 0 ? 0 : positionMagnifier); - positionMagnifier *= 2; - } - return decimalNumber; -} \ No newline at end of file diff --git "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.h" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.h" deleted file mode 100644 index 357a1e7..0000000 --- "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.h" +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -//function for writing the digits of a number to an array. -//The digits are the binary representation of the number numberToWrite is written to the array arrayOfNumber -void writeDigitsToArray(int* arrayOfNumber, int numberToWrite); - -// function for outputting the digits of a number in binary form -void outputtingNumberInBinaryNotation(int* arrayOfNumber); - -// function for adding numbers in the binary number system -void additionOfDigitsOfTwoNumbers(int* arrayOfDigitsOfTheFirstNumber, int* arrayOfDigitsOfTheSecondNumber, int* arrayForWritingTheSumOfDigits); - -// function to convert a number from binary to decimal -int convertNumberFromBinaryToDecimal(int* arrayForWritingTheSumOfDigits); \ No newline at end of file diff --git "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/main.c" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/main.c" deleted file mode 100644 index 914646a..0000000 --- "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/main.c" +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include "binaryNumberSystem.h" -#include "tests.h" - -int main() -{ - setlocale(LC_ALL, "rus"); - if (!testWritingDigitsToArray() || !testAdditionOfDigitsOfTwoNumbers() || !testConvertNumberFromBinaryToDecimal()) - { - printf("Tec "); - return -1; - } - int firstNumber = 0; - printf(" \n"); - const int scanfFirstNumberResult = scanf_s("%d", &firstNumber); - if (scanfFirstNumberResult == 0) - { - return -1; - } - int secondNumber = 0; - printf(" \n"); - const int scanfSecondNumberResult = scanf_s("%d", &secondNumber); - if (scanfSecondNumberResult == 0) - { - return -1; - } - - int arrayForWritingTheDigitsOfFirstNumber[8 * sizeof(int)] = { 0 }; - writeDigitsToArray(arrayForWritingTheDigitsOfFirstNumber, firstNumber); - printf(" 2 : "); - outputtingNumberInBinaryNotation(arrayForWritingTheDigitsOfFirstNumber); - printf("\n\n"); - - int arrayForWritingTheDigitsOfSecondNumber[8 * sizeof(int)] = { 0 }; - writeDigitsToArray(arrayForWritingTheDigitsOfSecondNumber, secondNumber); - printf(" 2 : "); - outputtingNumberInBinaryNotation(arrayForWritingTheDigitsOfSecondNumber); - printf("\n\n"); - - int arrayForWritingTheSumOfDigits[8 * sizeof(int)] = { 0 }; - additionOfDigitsOfTwoNumbers(arrayForWritingTheDigitsOfFirstNumber, arrayForWritingTheDigitsOfSecondNumber, arrayForWritingTheSumOfDigits); - printf(" 2 : "); - outputtingNumberInBinaryNotation(arrayForWritingTheSumOfDigits); - printf("\n\n"); - printf(" 10 : %d", convertNumberFromBinaryToDecimal(arrayForWritingTheSumOfDigits)); -} - diff --git "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.c" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.c" deleted file mode 100644 index 05f73e1..0000000 --- "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.c" +++ /dev/null @@ -1,67 +0,0 @@ -#include "tests.h" -#include "binaryNumberSystem.h" - -bool comparingDigitsInArrays(int* firstArrayOfDigits, int* secondArrayOFDigits) -{ - for(int j = 0; j < sizeof(int) * 8; j++) - { - if (firstArrayOfDigits[j] != secondArrayOFDigits[j]) - { - return false; - } - } - return true; -} - -bool testWritingDigitsToArray() -{ - // check for writing positive numbers - int representationOfNumber31[sizeof(int) * 8] = { 1, 1, 1, 1, 1 }; - int arrayForWritingTheNumber31[sizeof(int) * 8] = { 0 }; - writeDigitsToArray(arrayForWritingTheNumber31, 31); - int representationOfNumber123[sizeof(int) * 8] = { 1, 1, 0, 1, 1, 1, 1 }; - int arrayForWritingTheNumber123[sizeof(int) * 8] = { 0 }; - writeDigitsToArray(arrayForWritingTheNumber123, 123); - - // check for writing negative numbers - int representationOfNumberMinus12[sizeof(int) * 8] = { 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; - int arrayForWritingTheNumberMinus12[sizeof(int) * 8] = { 0 }; - writeDigitsToArray(arrayForWritingTheNumberMinus12, -12); - int representationOfNumberMinus245[sizeof(int) * 8] = { 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; - int arrayForWritingTheNumberMinus245[sizeof(int) * 8] = { 0 }; - writeDigitsToArray(arrayForWritingTheNumberMinus245, -245); - - return comparingDigitsInArrays(representationOfNumber31, arrayForWritingTheNumber31) - && comparingDigitsInArrays(representationOfNumber123, arrayForWritingTheNumber123) - && comparingDigitsInArrays(representationOfNumberMinus12, arrayForWritingTheNumberMinus12) - && comparingDigitsInArrays(representationOfNumberMinus245, arrayForWritingTheNumberMinus245); -} - -bool testAdditionOfDigitsOfTwoNumbers() -{ - int representationOfNumber31[sizeof(int) * 8] = { 1, 1, 1, 1, 1 }; - int representationOfNumberMinus12[sizeof(int) * 8] = { 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; - int representationOfNumber19[sizeof(int) * 8] = { 1, 1, 0, 0, 1 }; - int arrayForWritingTheNumber19[sizeof(int) * 8] = { 0 }; - - int representationOfNumberMinus245[sizeof(int) * 8] = { 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; - int representationOfNumber123[sizeof(int) * 8] = { 1, 1, 0, 1, 1, 1, 1 }; - int representationOfNumberMinus122[sizeof(int) * 8] = { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; - int arrayForWritingTheNumberMinus122[sizeof(int) * 8] = { 0 }; - - additionOfDigitsOfTwoNumbers(representationOfNumber31, representationOfNumberMinus12, arrayForWritingTheNumber19); - additionOfDigitsOfTwoNumbers(representationOfNumberMinus245, representationOfNumber123, arrayForWritingTheNumberMinus122); - - return comparingDigitsInArrays(representationOfNumberMinus122, arrayForWritingTheNumberMinus122) - && comparingDigitsInArrays(representationOfNumber19, arrayForWritingTheNumber19); -} - -bool testConvertNumberFromBinaryToDecimal() -{ - int representationOfNumber31[sizeof(int) * 8] = { 1, 1, 1, 1, 1 }; - int representationOfNumberMinus12[sizeof(int) * 8] = { 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; - int representationOfNumber19[sizeof(int) * 8] = { 1, 1, 0, 0, 1 }; - return convertNumberFromBinaryToDecimal(representationOfNumber19) == 19 - && convertNumberFromBinaryToDecimal(representationOfNumber31) == 31 - && convertNumberFromBinaryToDecimal(representationOfNumberMinus12) == -12; -} \ No newline at end of file diff --git "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.h" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.h" deleted file mode 100644 index 568156e..0000000 --- "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.h" +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#include - -// function to check the correct translation of a number into a binary system -bool testWritingDigitsToArray(); - -// function for checking the correct addition of two numbers in a binary system -bool testAdditionOfDigitsOfTwoNumbers(); - -// function for checking the correct conversion of a number to the decimal system -bool testConvertNumberFromBinaryToDecimal(); From 5d96a32708bc2fea6c50d11544c9f997111205a1 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 26 Nov 2021 13:50:46 +0300 Subject: [PATCH 5/6] Revert "deleting unnecessary files" This reverts commit 9aab49197bc4d3687d640ac9196a40345d7c067f. --- "Homework \342\204\2261/Array/Array.sln" | 31 ++ "Homework \342\204\2261/Array/Array/Array.c" | 18 + .../Array/Array/Array.vcxproj" | 147 +++++++ .../Array/Array/Array.vcxproj.filters" | 22 + "Homework \342\204\2261/Balance/Balance.sln" | 31 ++ .../Balance/Balance/Balance.vcxproj" | 147 +++++++ .../Balance/Balance/Balance.vcxproj.filters" | 22 + .../Balance/Balance/balance.c" | 33 ++ .../Division/Division.sln" | 31 ++ .../Division/Division/Division.c" | 84 ++++ .../Division/Division/Division.vcxproj" | 147 +++++++ .../Division/Division.vcxproj.filters" | 22 + "Homework \342\204\2261/Number/Number.sln" | 31 ++ .../Number/Number/Number.c" | 35 ++ .../Number/Number/Number.vcxproj" | 147 +++++++ .../Number/Number/Number.vcxproj.filters" | 22 + .../Ssection/Ssection.sln" | 31 ++ .../Ssection/Ssection/Section.c" | 46 +++ .../Ssection/Ssection/Ssection.vcxproj" | 147 +++++++ .../Ssection/Ssection.vcxproj.filters" | 22 + "Homework \342\204\2261/String/String.sln" | 31 ++ .../String/String/String.c" | 57 +++ .../String/String/String.vcxproj" | 147 +++++++ .../String/String/String.vcxproj.filters" | 22 + .../Swap/Swap.sln" | 20 +- "Homework \342\204\2261/Swap/Swap/Swap.c" | 15 + .../Swap/Swap/Swap.vcxproj" | 147 +++++++ .../Swap/Swap/Swap.vcxproj.filters" | 22 + "Homework \342\204\2261/Tickets/Tickets.sln" | 31 ++ .../Tickets/Tickets/Tickets.c" | 32 ++ .../Tickets/Tickets/Tickets.vcxproj" | 147 +++++++ .../Tickets/Tickets/Tickets.vcxproj.filters" | 22 + .../CountAndBubbleSort.sln" | 31 ++ .../CountAndBubbleSort/CountAndBubbleSort.c" | 214 ++++++++++ .../CountAndBubbleSort.vcxproj" | 147 +++++++ .../CountAndBubbleSort.vcxproj.filters" | 22 + .../CountAndBubbleSort.vcxproj.user" | 4 + "Homework \342\204\2262/Extent/Extent.sln" | 31 ++ .../Extent/Extent/Extent.vcxproj" | 148 +++++++ .../Extent/Extent/Extent.vcxproj.filters" | 22 + .../Extent/Extent/Extent.vcxproj.user" | 4 + .../Extent/Extent/extent.c" | 117 ++++++ .../Fibonacci/Fibonacci.sln" | 31 ++ .../Fibonacci/Fibonacci/Fibonacci.c" | 79 ++++ .../Fibonacci/Fibonacci/Fibonacci.vcxproj" | 147 +++++++ .../Fibonacci/Fibonacci.vcxproj.filters" | 22 + .../Fibonacci/Fibonacci.vcxproj.user" | 4 + .../semiQSort/semiQSort.sln" | 31 ++ .../semiQSort/semiQSort/semiQSort.c" | 119 ++++++ .../semiQSort/semiQSort/semiQSort.vcxproj" | 147 +++++++ .../semiQSort/semiQSort.vcxproj.filters" | 22 + .../semiQSort/semiQSort.vcxproj.user" | 4 + .../binarySearch/binarySearch.sln" | 31 ++ .../binarySearch/binarySearch/binary.h" | 8 + .../binarySearch/binarySearch/binarySearch.c" | 61 +++ .../binarySearch/binarySearch.vcxproj" | 153 +++++++ .../binarySearch.vcxproj.filters" | 10 +- .../binarySearch/binarySearch/main.c" | 36 ++ .../binarySearch/binarySearch/qsort.c" | 107 +++++ .../binarySearch/binarySearch/qsort.h" | 15 + .../quickSort/quickSort.sln" | 31 ++ .../quickSort/quickSort/quickSort.vcxproj" | 147 +++++++ .../quickSort/quickSort.vcxproj.filters" | 22 + .../quickSort/quickSort/quicksort.c" | 136 +++++++ .../theMostCommonElement.sln" | 31 ++ .../TheMostCommonElement.c" | 33 ++ .../TheMostCommonElement.h" | 4 + .../theMostCommonElement/main.c" | 28 ++ .../theMostCommonElement/qsort.c" | 64 +++ .../theMostCommonElement/qsort.h" | 4 + .../theMostCommonElement/test.h" | 8 + .../theMostCommonElement/tests.c" | 70 ++++ .../theMostCommonElement.vcxproj" | 155 +++++++ .../theMostCommonElement.vcxproj.filters" | 42 ++ .../Phonebook/Phonebook.sln" | 31 ++ .../Phonebook/Phonebook/Phonebook.vcxproj" | 18 +- .../Phonebook/Phonebook.vcxproj.filters" | 36 ++ .../Phonebook/Phonebook/main.c" | 128 ++++++ .../Phonebook/Phonebook/phoneBook.c" | 90 +++++ .../Phonebook/Phonebook/phoneBook.h" | 27 ++ .../Phonebook/Phonebook/phoneNumber.txt" | 19 + .../Phonebook/Phonebook/test1.txt" | 4 + .../Phonebook/Phonebook/tests.c" | 34 ++ .../Phonebook/Phonebook/tests.h" | 5 + .../additionOfNumbers/additionOfNumbers.sln" | 31 ++ .../additionOfNumbers.vcxproj" | 153 +++++++ .../additionOfNumbers.vcxproj.filters" | 36 ++ .../additionOfNumbers/binaryNumberSystem.c" | 49 +++ .../additionOfNumbers/binaryNumberSystem.h" | 14 + .../additionOfNumbers/main.c" | 48 +++ .../additionOfNumbers/tests.c" | 67 ++++ .../additionOfNumbers/tests.h" | 11 + Tree/Tree/Main.c | 10 - Tree/Tree/TestTree.c | 91 ----- Tree/Tree/TestTree.h | 14 - Tree/Tree/Tree.c | 377 ------------------ Tree/Tree/Tree.h | 33 -- 97 files changed, 5228 insertions(+), 549 deletions(-) create mode 100644 "Homework \342\204\2261/Array/Array.sln" create mode 100644 "Homework \342\204\2261/Array/Array/Array.c" create mode 100644 "Homework \342\204\2261/Array/Array/Array.vcxproj" create mode 100644 "Homework \342\204\2261/Array/Array/Array.vcxproj.filters" create mode 100644 "Homework \342\204\2261/Balance/Balance.sln" create mode 100644 "Homework \342\204\2261/Balance/Balance/Balance.vcxproj" create mode 100644 "Homework \342\204\2261/Balance/Balance/Balance.vcxproj.filters" create mode 100644 "Homework \342\204\2261/Balance/Balance/balance.c" create mode 100644 "Homework \342\204\2261/Division/Division.sln" create mode 100644 "Homework \342\204\2261/Division/Division/Division.c" create mode 100644 "Homework \342\204\2261/Division/Division/Division.vcxproj" create mode 100644 "Homework \342\204\2261/Division/Division/Division.vcxproj.filters" create mode 100644 "Homework \342\204\2261/Number/Number.sln" create mode 100644 "Homework \342\204\2261/Number/Number/Number.c" create mode 100644 "Homework \342\204\2261/Number/Number/Number.vcxproj" create mode 100644 "Homework \342\204\2261/Number/Number/Number.vcxproj.filters" create mode 100644 "Homework \342\204\2261/Ssection/Ssection.sln" create mode 100644 "Homework \342\204\2261/Ssection/Ssection/Section.c" create mode 100644 "Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj" create mode 100644 "Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj.filters" create mode 100644 "Homework \342\204\2261/String/String.sln" create mode 100644 "Homework \342\204\2261/String/String/String.c" create mode 100644 "Homework \342\204\2261/String/String/String.vcxproj" create mode 100644 "Homework \342\204\2261/String/String/String.vcxproj.filters" rename Tree/Tree.sln => "Homework \342\204\2261/Swap/Swap.sln" (50%) create mode 100644 "Homework \342\204\2261/Swap/Swap/Swap.c" create mode 100644 "Homework \342\204\2261/Swap/Swap/Swap.vcxproj" create mode 100644 "Homework \342\204\2261/Swap/Swap/Swap.vcxproj.filters" create mode 100644 "Homework \342\204\2261/Tickets/Tickets.sln" create mode 100644 "Homework \342\204\2261/Tickets/Tickets/Tickets.c" create mode 100644 "Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj" create mode 100644 "Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj.filters" create mode 100644 "Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort.sln" create mode 100644 "Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.c" create mode 100644 "Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj" create mode 100644 "Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.filters" create mode 100644 "Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.user" create mode 100644 "Homework \342\204\2262/Extent/Extent.sln" create mode 100644 "Homework \342\204\2262/Extent/Extent/Extent.vcxproj" create mode 100644 "Homework \342\204\2262/Extent/Extent/Extent.vcxproj.filters" create mode 100644 "Homework \342\204\2262/Extent/Extent/Extent.vcxproj.user" create mode 100644 "Homework \342\204\2262/Extent/Extent/extent.c" create mode 100644 "Homework \342\204\2262/Fibonacci/Fibonacci.sln" create mode 100644 "Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.c" create mode 100644 "Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj" create mode 100644 "Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.filters" create mode 100644 "Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.user" create mode 100644 "Homework \342\204\2262/semiQSort/semiQSort.sln" create mode 100644 "Homework \342\204\2262/semiQSort/semiQSort/semiQSort.c" create mode 100644 "Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj" create mode 100644 "Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.filters" create mode 100644 "Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.user" create mode 100644 "Homework \342\204\2263/binarySearch/binarySearch.sln" create mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/binary.h" create mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/binarySearch.c" create mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj" rename Tree/Tree/Tree.vcxproj.filters => "Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj.filters" (87%) create mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/main.c" create mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/qsort.c" create mode 100644 "Homework \342\204\2263/binarySearch/binarySearch/qsort.h" create mode 100644 "Homework \342\204\2263/quickSort/quickSort.sln" create mode 100644 "Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj" create mode 100644 "Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj.filters" create mode 100644 "Homework \342\204\2263/quickSort/quickSort/quicksort.c" create mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement.sln" create mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.c" create mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.h" create mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/main.c" create mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.c" create mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.h" create mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/test.h" create mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/tests.c" create mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj" create mode 100644 "Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj.filters" create mode 100644 "Homework \342\204\2264/Phonebook/Phonebook.sln" rename Tree/Tree/Tree.vcxproj => "Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj" (92%) create mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj.filters" create mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/main.c" create mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/phoneBook.c" create mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/phoneBook.h" create mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/phoneNumber.txt" create mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/test1.txt" create mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/tests.c" create mode 100644 "Homework \342\204\2264/Phonebook/Phonebook/tests.h" create mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers.sln" create mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj" create mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj.filters" create mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.c" create mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.h" create mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/main.c" create mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.c" create mode 100644 "Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.h" delete mode 100644 Tree/Tree/Main.c delete mode 100644 Tree/Tree/TestTree.c delete mode 100644 Tree/Tree/TestTree.h delete mode 100644 Tree/Tree/Tree.c delete mode 100644 Tree/Tree/Tree.h diff --git "a/Homework \342\204\2261/Array/Array.sln" "b/Homework \342\204\2261/Array/Array.sln" new file mode 100644 index 0000000..1575323 --- /dev/null +++ "b/Homework \342\204\2261/Array/Array.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}") = "Array", "Array\Array.vcxproj", "{237C1E80-EEBB-4E9D-8754-268C34E50000}" +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 + {237C1E80-EEBB-4E9D-8754-268C34E50000}.Debug|x64.ActiveCfg = Debug|x64 + {237C1E80-EEBB-4E9D-8754-268C34E50000}.Debug|x64.Build.0 = Debug|x64 + {237C1E80-EEBB-4E9D-8754-268C34E50000}.Debug|x86.ActiveCfg = Debug|Win32 + {237C1E80-EEBB-4E9D-8754-268C34E50000}.Debug|x86.Build.0 = Debug|Win32 + {237C1E80-EEBB-4E9D-8754-268C34E50000}.Release|x64.ActiveCfg = Release|x64 + {237C1E80-EEBB-4E9D-8754-268C34E50000}.Release|x64.Build.0 = Release|x64 + {237C1E80-EEBB-4E9D-8754-268C34E50000}.Release|x86.ActiveCfg = Release|Win32 + {237C1E80-EEBB-4E9D-8754-268C34E50000}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9DF372F6-37E4-4FE8-B6E3-CFF5D4A7944B} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2261/Array/Array/Array.c" "b/Homework \342\204\2261/Array/Array/Array.c" new file mode 100644 index 0000000..8619d13 --- /dev/null +++ "b/Homework \342\204\2261/Array/Array/Array.c" @@ -0,0 +1,18 @@ +#include + +int main() +{ + int arrayOfNumbers[100] = {0}; + int numberZeroValues = 0; + for (int i = 0; i < 100; i++) + { + // we assign random values from 0 to 9 to the elements of the array + arrayOfNumbers[i] = rand() % 10; + // if the value of an array element is 0, we increase the counter of zero elements by 1 + if (arrayOfNumbers[i] == 0) + { + numberZeroValues++; + } + } + printf("The number of zero elements in the array = %d", numberZeroValues); +} \ No newline at end of file diff --git "a/Homework \342\204\2261/Array/Array/Array.vcxproj" "b/Homework \342\204\2261/Array/Array/Array.vcxproj" new file mode 100644 index 0000000..34969d4 --- /dev/null +++ "b/Homework \342\204\2261/Array/Array/Array.vcxproj" @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {237c1e80-eebb-4e9d-8754-268c34e50000} + Array + 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/Homework \342\204\2261/Array/Array/Array.vcxproj.filters" "b/Homework \342\204\2261/Array/Array/Array.vcxproj.filters" new file mode 100644 index 0000000..782aede --- /dev/null +++ "b/Homework \342\204\2261/Array/Array/Array.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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\2261/Balance/Balance.sln" "b/Homework \342\204\2261/Balance/Balance.sln" new file mode 100644 index 0000000..f2e3e26 --- /dev/null +++ "b/Homework \342\204\2261/Balance/Balance.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}") = "Balance", "Balance\Balance.vcxproj", "{3372BD3C-C97A-432C-8601-2B136B61FC99}" +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 + {3372BD3C-C97A-432C-8601-2B136B61FC99}.Debug|x64.ActiveCfg = Debug|x64 + {3372BD3C-C97A-432C-8601-2B136B61FC99}.Debug|x64.Build.0 = Debug|x64 + {3372BD3C-C97A-432C-8601-2B136B61FC99}.Debug|x86.ActiveCfg = Debug|Win32 + {3372BD3C-C97A-432C-8601-2B136B61FC99}.Debug|x86.Build.0 = Debug|Win32 + {3372BD3C-C97A-432C-8601-2B136B61FC99}.Release|x64.ActiveCfg = Release|x64 + {3372BD3C-C97A-432C-8601-2B136B61FC99}.Release|x64.Build.0 = Release|x64 + {3372BD3C-C97A-432C-8601-2B136B61FC99}.Release|x86.ActiveCfg = Release|Win32 + {3372BD3C-C97A-432C-8601-2B136B61FC99}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {06E3F097-DF24-4285-ABF2-0EF1902D316E} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2261/Balance/Balance/Balance.vcxproj" "b/Homework \342\204\2261/Balance/Balance/Balance.vcxproj" new file mode 100644 index 0000000..b67bee6 --- /dev/null +++ "b/Homework \342\204\2261/Balance/Balance/Balance.vcxproj" @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {3372bd3c-c97a-432c-8601-2b136b61fc99} + Balance + 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/Homework \342\204\2261/Balance/Balance/Balance.vcxproj.filters" "b/Homework \342\204\2261/Balance/Balance/Balance.vcxproj.filters" new file mode 100644 index 0000000..3ec152a --- /dev/null +++ "b/Homework \342\204\2261/Balance/Balance/Balance.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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\2261/Balance/Balance/balance.c" "b/Homework \342\204\2261/Balance/Balance/balance.c" new file mode 100644 index 0000000..7b3c065 --- /dev/null +++ "b/Homework \342\204\2261/Balance/Balance/balance.c" @@ -0,0 +1,33 @@ +#include + +int main() +{ + char stringBrackets[100] = {'\0'}; + gets(stringBrackets); + int counterBrakets = 0; + int counterCycle = 0; + + while(counterBrakets >= 0 && stringBrackets[counterCycle] != '\0') + { + // if the bracket is opening, then we increase the counter value by 1 + if (stringBrackets[counterCycle] == '(') + { + counterBrakets++; + } + // otherwise, we reduce the counter value by 1 + else if (stringBrackets[counterCycle] == ')') + { + counterBrakets--; + } + counterCycle++; + } + + if (counterBrakets == 0) + { + printf("The rule of nesting brackets is observed."); + } + else + { + printf("The rule of nesting brackets is not observed."); + } +} \ No newline at end of file diff --git "a/Homework \342\204\2261/Division/Division.sln" "b/Homework \342\204\2261/Division/Division.sln" new file mode 100644 index 0000000..2f0a2d8 --- /dev/null +++ "b/Homework \342\204\2261/Division/Division.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}") = "Division", "Division\Division.vcxproj", "{E1AB46C9-95F5-4284-9487-B90A7AE1B785}" +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 + {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Debug|x64.ActiveCfg = Debug|x64 + {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Debug|x64.Build.0 = Debug|x64 + {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Debug|x86.ActiveCfg = Debug|Win32 + {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Debug|x86.Build.0 = Debug|Win32 + {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Release|x64.ActiveCfg = Release|x64 + {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Release|x64.Build.0 = Release|x64 + {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Release|x86.ActiveCfg = Release|Win32 + {E1AB46C9-95F5-4284-9487-B90A7AE1B785}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {060FAA4C-3486-4299-86E2-282A3924D91E} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2261/Division/Division/Division.c" "b/Homework \342\204\2261/Division/Division/Division.c" new file mode 100644 index 0000000..4e35eac --- /dev/null +++ "b/Homework \342\204\2261/Division/Division/Division.c" @@ -0,0 +1,84 @@ +#include +#include + +void printQuotientDivision(int counter) +{ + printf("quotient of division = %d", counter); +} + +int main() +{ + int a = 0; + int b = 0; + printf("enter dividend \n"); + const int firstScanfResultA = scanf_s("%d", &a); + if (firstScanfResultA == 0) + { + printf("had to enter a number"); + return 0; + } + + printf("enter the divisor\n"); + const int firstScanfResultB = scanf_s("%d", &b); + if (!firstScanfResultB) + { + printf("had to enter a number"); + return 0; + } + + if (b == 0) + { + printf("you can't divide by 0"); + return 0; + } + + if (a == 0 && b!= 0) + { + printQuotientDivision(0); + return 0; + } + + if (a == b) + { + printQuotientDivision(1); + return 0; + } + + if (a == -b) + { + printQuotientDivision(-1); + return 0; + } + + int subtractionounter = 0; + int absoluteValueA = abs(a); + int absoluteValueB = abs(b); + + while (absoluteValueA - absoluteValueB > 0) + { + absoluteValueA -= absoluteValueB; + subtractionounter++; + } + + if (a > 0 && b < 0) + { + printQuotientDivision(-subtractionounter); + } + + if (a < 0 && b > 0) + { + printQuotientDivision(-subtractionounter - 1); + } + + if (a > 0 && b > 0) + { + printQuotientDivision(subtractionounter); + } + + if (a < 0 && b < 0) + { + printQuotientDivision(subtractionounter + 1); + } + + return 0; +} \ No newline at end of file diff --git "a/Homework \342\204\2261/Division/Division/Division.vcxproj" "b/Homework \342\204\2261/Division/Division/Division.vcxproj" new file mode 100644 index 0000000..fa75c2f --- /dev/null +++ "b/Homework \342\204\2261/Division/Division/Division.vcxproj" @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {e1ab46c9-95f5-4284-9487-b90a7ae1b785} + Division + 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/Homework \342\204\2261/Division/Division/Division.vcxproj.filters" "b/Homework \342\204\2261/Division/Division/Division.vcxproj.filters" new file mode 100644 index 0000000..77eca4f --- /dev/null +++ "b/Homework \342\204\2261/Division/Division/Division.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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\2261/Number/Number.sln" "b/Homework \342\204\2261/Number/Number.sln" new file mode 100644 index 0000000..e64c8c6 --- /dev/null +++ "b/Homework \342\204\2261/Number/Number.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}") = "Number", "Number\Number.vcxproj", "{06765B58-98FC-456B-AA35-559A61EC159D}" +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 + {06765B58-98FC-456B-AA35-559A61EC159D}.Debug|x64.ActiveCfg = Debug|x64 + {06765B58-98FC-456B-AA35-559A61EC159D}.Debug|x64.Build.0 = Debug|x64 + {06765B58-98FC-456B-AA35-559A61EC159D}.Debug|x86.ActiveCfg = Debug|Win32 + {06765B58-98FC-456B-AA35-559A61EC159D}.Debug|x86.Build.0 = Debug|Win32 + {06765B58-98FC-456B-AA35-559A61EC159D}.Release|x64.ActiveCfg = Release|x64 + {06765B58-98FC-456B-AA35-559A61EC159D}.Release|x64.Build.0 = Release|x64 + {06765B58-98FC-456B-AA35-559A61EC159D}.Release|x86.ActiveCfg = Release|Win32 + {06765B58-98FC-456B-AA35-559A61EC159D}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DFE5B96D-0446-4BDB-B38F-FFDCF0D327CE} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2261/Number/Number/Number.c" "b/Homework \342\204\2261/Number/Number/Number.c" new file mode 100644 index 0000000..913549c --- /dev/null +++ "b/Homework \342\204\2261/Number/Number/Number.c" @@ -0,0 +1,35 @@ +#include +#include + +int main() +{ + int number = 0; + printf("Enter a positive integer\n"); + scanf_s("%d", &number); + // if the number is non-positive, then it has no divisors + if (number <= 0) + { + printf("It was necessary to enter a positive number"); + return 0; + } + // brute force for numbers from 1 to number + for (int i = 1; i <= number; i++) + { + const int rootOfTheNumber = sqrt(i); + // for each i, we are looking for divisors from 1 to sqrt(i) + for (int j = 1; j <= rootOfTheNumber; j++) + { + // if a number from 1 to number has a divisor j that is not equal to 1, then this number is composite + if (i % j == 0 && j != 1) + { + // since the number is composite, it makes no sense to look for its other divisors, exit the loop + break; + } + // we continue until j is equal to the number floor(sqrt(i)) (in this case, the number is prime) + if (j == floor(sqrt(i))) + { + printf("%d\n", i); + } + } + } +} \ No newline at end of file diff --git "a/Homework \342\204\2261/Number/Number/Number.vcxproj" "b/Homework \342\204\2261/Number/Number/Number.vcxproj" new file mode 100644 index 0000000..7c803a3 --- /dev/null +++ "b/Homework \342\204\2261/Number/Number/Number.vcxproj" @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {06765b58-98fc-456b-aa35-559a61ec159d} + Number + 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/Homework \342\204\2261/Number/Number/Number.vcxproj.filters" "b/Homework \342\204\2261/Number/Number/Number.vcxproj.filters" new file mode 100644 index 0000000..6afdaa3 --- /dev/null +++ "b/Homework \342\204\2261/Number/Number/Number.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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\2261/Ssection/Ssection.sln" "b/Homework \342\204\2261/Ssection/Ssection.sln" new file mode 100644 index 0000000..3745e20 --- /dev/null +++ "b/Homework \342\204\2261/Ssection/Ssection.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}") = "Ssection", "Ssection\Ssection.vcxproj", "{B24E5472-F4B3-4E47-A7FA-60D3037367CF}" +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 + {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Debug|x64.ActiveCfg = Debug|x64 + {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Debug|x64.Build.0 = Debug|x64 + {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Debug|x86.ActiveCfg = Debug|Win32 + {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Debug|x86.Build.0 = Debug|Win32 + {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Release|x64.ActiveCfg = Release|x64 + {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Release|x64.Build.0 = Release|x64 + {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Release|x86.ActiveCfg = Release|Win32 + {B24E5472-F4B3-4E47-A7FA-60D3037367CF}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1F3DCF66-94B1-4620-B212-A22A95DEC463} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2261/Ssection/Ssection/Section.c" "b/Homework \342\204\2261/Ssection/Ssection/Section.c" new file mode 100644 index 0000000..0f7ba39 --- /dev/null +++ "b/Homework \342\204\2261/Ssection/Ssection/Section.c" @@ -0,0 +1,46 @@ +#include +#include + +// A function for inverting array values that depends on the number of the first element in the segment and the number of elements in the array +void flipNumbersArray(int firstElement, int numberOfElements, int* arrayOfNumbers) +{ + for (int i = firstElement; i < numberOfElements / 2; i++) + { + const int temporary = arrayOfNumbers[i]; + arrayOfNumbers[i] = arrayOfNumbers[numberOfElements - 1 - i]; + arrayOfNumbers[numberOfElements - 1 - i] = temporary; + } +} + +void printNumbersArray(int numberOfElements, int* arrayOfNumbers) +{ + for (int i = 0; i < numberOfElements; i++) + { + printf(" %d", arrayOfNumbers[i]); + } +} + +int main() +{ + int numberOfElements = 0; + printf("Enter the number of elements in the array\n"); + scanf_s("%d", &numberOfElements); + // allocation of dynamic memory for entering the number of elements in the array from the keyboard + int* arrayOfNumbers = (int*)malloc(numberOfElements * sizeof(int)); + printf("The segment of what length do you want to move to the end?\n"); + int m = 0; + scanf_s("%d", &m); + + for (int i = 0; i < numberOfElements; i++) + { + arrayOfNumbers[i] = rand() % 10; + } + + printNumbersArray(numberOfElements, arrayOfNumbers); + flipNumbersArray(0, m, arrayOfNumbers); + flipNumbersArray(m, numberOfElements + m, arrayOfNumbers); + flipNumbersArray(0, numberOfElements , arrayOfNumbers); + printf("\n\n\n"); + printNumbersArray(numberOfElements, arrayOfNumbers); + free(arrayOfNumbers); +} diff --git "a/Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj" "b/Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj" new file mode 100644 index 0000000..df1cd23 --- /dev/null +++ "b/Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj" @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {b24e5472-f4b3-4e47-a7fa-60d3037367cf} + Ssection + 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/Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj.filters" "b/Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj.filters" new file mode 100644 index 0000000..0b4a350 --- /dev/null +++ "b/Homework \342\204\2261/Ssection/Ssection/Ssection.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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\2261/String/String.sln" "b/Homework \342\204\2261/String/String.sln" new file mode 100644 index 0000000..1a0c6a9 --- /dev/null +++ "b/Homework \342\204\2261/String/String.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}") = "String", "String\String.vcxproj", "{F28DB431-02D6-423A-AD87-08796F891FA1}" +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 + {F28DB431-02D6-423A-AD87-08796F891FA1}.Debug|x64.ActiveCfg = Debug|x64 + {F28DB431-02D6-423A-AD87-08796F891FA1}.Debug|x64.Build.0 = Debug|x64 + {F28DB431-02D6-423A-AD87-08796F891FA1}.Debug|x86.ActiveCfg = Debug|Win32 + {F28DB431-02D6-423A-AD87-08796F891FA1}.Debug|x86.Build.0 = Debug|Win32 + {F28DB431-02D6-423A-AD87-08796F891FA1}.Release|x64.ActiveCfg = Release|x64 + {F28DB431-02D6-423A-AD87-08796F891FA1}.Release|x64.Build.0 = Release|x64 + {F28DB431-02D6-423A-AD87-08796F891FA1}.Release|x86.ActiveCfg = Release|Win32 + {F28DB431-02D6-423A-AD87-08796F891FA1}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D33770E3-4529-4E2C-898F-05D35A9758E0} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2261/String/String/String.c" "b/Homework \342\204\2261/String/String/String.c" new file mode 100644 index 0000000..5a9c416 --- /dev/null +++ "b/Homework \342\204\2261/String/String/String.c" @@ -0,0 +1,57 @@ +#include +#include +#include + +int main() +{ + setlocale(LC_ALL, "Rus"); + int matchingSymbolsCount = 0; + int occurrencesCount = 0; + char s[100] = {'\0'}; + char s1[100] = {'\0'}; + printf(" S "); + gets(s); + printf(" S1 "); + gets(s1); + // S + const int lineLengthS = strlen(s); + // S1 + const int lineLengthS1 = strlen(s1); + + // S1 > S + if (lineLengthS / lineLengthS1 < 1) + { + printf(" s1 = 0"); + return 0; + } + + for (int i = 0; i < lineLengthS - lineLengthS1 + 1; i++) + { + // S S1 + if (s[i] == s1[0]) + { + // + for (int l = 0; l <= lineLengthS1 - 1; l++) + { + if (s[i + l] == s1[l]) + { + // + matchingSymbolsCount++; + + // S1, 1 + if (matchingSymbolsCount == lineLengthS1) + { + occurrencesCount++; + matchingSymbolsCount = 0; + } + } + else + { + break; + } + } + } + } + printf(" S1 = %d", occurrencesCount); + return 0; +} \ No newline at end of file diff --git "a/Homework \342\204\2261/String/String/String.vcxproj" "b/Homework \342\204\2261/String/String/String.vcxproj" new file mode 100644 index 0000000..0c995da --- /dev/null +++ "b/Homework \342\204\2261/String/String/String.vcxproj" @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {f28db431-02d6-423a-ad87-08796f891fa1} + String + 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/Homework \342\204\2261/String/String/String.vcxproj.filters" "b/Homework \342\204\2261/String/String/String.vcxproj.filters" new file mode 100644 index 0000000..00be40e --- /dev/null +++ "b/Homework \342\204\2261/String/String/String.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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/Tree/Tree.sln "b/Homework \342\204\2261/Swap/Swap.sln" similarity index 50% rename from Tree/Tree.sln rename to "Homework \342\204\2261/Swap/Swap.sln" index a09c740..0b5a831 100644 --- a/Tree/Tree.sln +++ "b/Homework \342\204\2261/Swap/Swap.sln" @@ -3,7 +3,7 @@ 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}") = "Tree", "Tree\Tree.vcxproj", "{1B08B554-064D-4A2D-A418-3C73FF3D4652}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Swap", "Swap\Swap.vcxproj", "{9A76EFB7-28EE-4317-AD9F-BB16463A313E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -13,19 +13,19 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Debug|x64.ActiveCfg = Debug|x64 - {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Debug|x64.Build.0 = Debug|x64 - {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Debug|x86.ActiveCfg = Debug|Win32 - {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Debug|x86.Build.0 = Debug|Win32 - {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Release|x64.ActiveCfg = Release|x64 - {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Release|x64.Build.0 = Release|x64 - {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Release|x86.ActiveCfg = Release|Win32 - {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Release|x86.Build.0 = Release|Win32 + {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Debug|x64.ActiveCfg = Debug|x64 + {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Debug|x64.Build.0 = Debug|x64 + {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Debug|x86.ActiveCfg = Debug|Win32 + {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Debug|x86.Build.0 = Debug|Win32 + {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Release|x64.ActiveCfg = Release|x64 + {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Release|x64.Build.0 = Release|x64 + {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Release|x86.ActiveCfg = Release|Win32 + {9A76EFB7-28EE-4317-AD9F-BB16463A313E}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {0EEF711C-36E8-4AC3-9FFA-66083037F612} + SolutionGuid = {CD05E673-AD0D-4132-BC37-722A0FFB733D} EndGlobalSection EndGlobal diff --git "a/Homework \342\204\2261/Swap/Swap/Swap.c" "b/Homework \342\204\2261/Swap/Swap/Swap.c" new file mode 100644 index 0000000..0807718 --- /dev/null +++ "b/Homework \342\204\2261/Swap/Swap/Swap.c" @@ -0,0 +1,15 @@ +#include + +int main() +{ + int x, y; + printf("Enter \n"); + scanf_s("%d", &x); + printf("Enter y\n"); + scanf_s("%d", &y); + x = x ^ y; + y = x ^ y; + x = x ^ y; + printf("new value x = %d\n", x); + printf("new value y = %d\n", y); +} \ No newline at end of file diff --git "a/Homework \342\204\2261/Swap/Swap/Swap.vcxproj" "b/Homework \342\204\2261/Swap/Swap/Swap.vcxproj" new file mode 100644 index 0000000..10993e8 --- /dev/null +++ "b/Homework \342\204\2261/Swap/Swap/Swap.vcxproj" @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {9a76efb7-28ee-4317-ad9f-bb16463a313e} + Swap + 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/Homework \342\204\2261/Swap/Swap/Swap.vcxproj.filters" "b/Homework \342\204\2261/Swap/Swap/Swap.vcxproj.filters" new file mode 100644 index 0000000..4e10e6a --- /dev/null +++ "b/Homework \342\204\2261/Swap/Swap/Swap.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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\2261/Tickets/Tickets.sln" "b/Homework \342\204\2261/Tickets/Tickets.sln" new file mode 100644 index 0000000..fcb81d8 --- /dev/null +++ "b/Homework \342\204\2261/Tickets/Tickets.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}") = "Tickets", "Tickets\Tickets.vcxproj", "{1FB8136F-1E7A-4C30-965B-E162FD9881C1}" +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 + {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Debug|x64.ActiveCfg = Debug|x64 + {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Debug|x64.Build.0 = Debug|x64 + {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Debug|x86.ActiveCfg = Debug|Win32 + {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Debug|x86.Build.0 = Debug|Win32 + {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Release|x64.ActiveCfg = Release|x64 + {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Release|x64.Build.0 = Release|x64 + {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Release|x86.ActiveCfg = Release|Win32 + {1FB8136F-1E7A-4C30-965B-E162FD9881C1}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {256FBE0C-5622-4F6D-ACEA-A17FE3CE3039} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2261/Tickets/Tickets/Tickets.c" "b/Homework \342\204\2261/Tickets/Tickets/Tickets.c" new file mode 100644 index 0000000..dbe4642 --- /dev/null +++ "b/Homework \342\204\2261/Tickets/Tickets/Tickets.c" @@ -0,0 +1,32 @@ +#include + +int main() +{ + int numberSumsDigits[28] = { 0 }; + int totalAmountTickets = 0; + + // use the for loop to find the sums of digits in the first 3-ex positions + for (int i = 0; i < 10; i++) + { + for (int j = 0; j < 10; j++) + { + for (int k = 0; k < 10; k++) + { + + // if the sum of digits i + j + k = n, then the number of sums with the value n is increased by one + ++numberSumsDigits[i + j + k]; + } + } + } + + for (int i = 0; i < 28; i++) + { + /* if there are p tickets on the first 3 positions for the sum i + j + k, the same number of tickets for the sum i + j + k + in the last 3 positions. As a result, for each sum, there are p ^ 2 such tickets */ + numberSumsDigits[i] *= numberSumsDigits[i]; + totalAmountTickets += numberSumsDigits[i]; + } + + printf("number of tickets = %d", totalAmountTickets); + return 0; +} \ No newline at end of file diff --git "a/Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj" "b/Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj" new file mode 100644 index 0000000..67d93f1 --- /dev/null +++ "b/Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj" @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {1fb8136f-1e7a-4c30-965b-e162fd9881c1} + Tickets + 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/Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj.filters" "b/Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj.filters" new file mode 100644 index 0000000..0cb924d --- /dev/null +++ "b/Homework \342\204\2261/Tickets/Tickets/Tickets.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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\2262/CountAndBubbleSort/CountAndBubbleSort.sln" "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort.sln" new file mode 100644 index 0000000..eac95a3 --- /dev/null +++ "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort.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}") = "CountAndBubbleSort", "CountAndBubbleSort\CountAndBubbleSort.vcxproj", "{A2AC6B8B-943F-4B6A-8130-896B08DF5092}" +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 + {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Debug|x64.ActiveCfg = Debug|x64 + {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Debug|x64.Build.0 = Debug|x64 + {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Debug|x86.ActiveCfg = Debug|Win32 + {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Debug|x86.Build.0 = Debug|Win32 + {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Release|x64.ActiveCfg = Release|x64 + {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Release|x64.Build.0 = Release|x64 + {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Release|x86.ActiveCfg = Release|Win32 + {A2AC6B8B-943F-4B6A-8130-896B08DF5092}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5235A9BF-195A-49C2-AFDA-DCEF76E17AD0} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.c" "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.c" new file mode 100644 index 0000000..fc0c003 --- /dev/null +++ "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.c" @@ -0,0 +1,214 @@ +#include +#include +#include +#include +#include + +// Function for sorting bubble +void bubbleSortArray(int* arrayOfNumbers, int numberOfElements) +{ + for (int i = 0; i < numberOfElements - 1; i++) + { + for (int j = numberOfElements - 1; j > i; j--) + { + if (arrayOfNumbers[j - 1] > arrayOfNumbers[j]) + { + const int temporary = arrayOfNumbers[j]; + arrayOfNumbers[j] = arrayOfNumbers[j - 1]; + arrayOfNumbers[j - 1] = temporary; + } + } + } +} + +// Function for sorting by counting +int countSortArray(int* arrayOfNumbers, int numberOfElements) +{ + // Finding the minimum element in the array + int minimumElementInArray = arrayOfNumbers[0]; + for (int i = 1; i <= numberOfElements - 1; i++) + { + if (arrayOfNumbers[i] < minimumElementInArray) + { + minimumElementInArray = arrayOfNumbers[i]; + } + } + + // Finding the maximum element in the array + int maximumElementInArray = arrayOfNumbers[0]; + for (int i = 1; i <= numberOfElements - 1; i++) + { + if (arrayOfNumbers[i] > maximumElementInArray) + { + maximumElementInArray = arrayOfNumbers[i]; + } + } + + // Allocation of dynamic memory for a counter array + int* arrayOfCount = (int*)calloc((maximumElementInArray - minimumElementInArray + 1), sizeof(int)); + + if (arrayOfCount == NULL) + { + return -1; + } + // For each element, we increase the counter for its value + for (int i = 0; i <= numberOfElements - 1; i++) + { + arrayOfCount[arrayOfNumbers[i] - minimumElementInArray]++; + } + int distributionounter = 0; + // For each i from the minimum value to the maximum, we write its value to the array sequentially arrayOfCount times + for (int i = minimumElementInArray; i <= maximumElementInArray; i++) + { + for (int j = 0; j < arrayOfCount[i - minimumElementInArray]; j++) + { + arrayOfNumbers[distributionounter] = i; + distributionounter++; + } + } + free(arrayOfCount); + return 0; +} + +bool sortingheck(int* arrayOfNumber, int numberOfElements) +{ + for (int i = 0; i < numberOfElements - 1; i++) + { + if (arrayOfNumber[i] > arrayOfNumber[i + 1]) + { + return false; + } + } + return true; +} + +// Function for testing bubble sorting +bool correctBubbleSort() +{ + // Checking the operation of sorts for a random set of numbers + int arrayOfNumbersForSorting[100] = { 0 }; + for (int i = 0; i < 100; i++) + { + arrayOfNumbersForSorting[i] = rand(); + } + bubbleSortArray(arrayOfNumbersForSorting, 100); + + // Checking the operation of sorts for an array consisting of equal numbers + int arrayOfEqualElements[40] = { 0 }; + for (int i = 0; i < 40; i++) + { + arrayOfEqualElements[i] = 144; + } + bubbleSortArray(arrayOfEqualElements, 40); + + // Checking the operation of sorts for a sorted array + int sortedArray[56] = { 0 }; + for (int i = 0; i < 56; i++) + { + sortedArray[i] = i; + } + bubbleSortArray(sortedArray, 56); + + // Checking the sorting operation for an array consisting of 1 element + int arrayOfOneElement[1] = { 138 }; + bubbleSortArray(arrayOfOneElement, 1); + + // Checking for an array of 0 elements + int arrayOfZeroElement[1] = { 138 }; + bubbleSortArray(arrayOfOneElement, 0); + + return sortingheck(arrayOfNumbersForSorting, 100) == 1 + && sortingheck(arrayOfEqualElements, 40) == 1 + && sortingheck(sortedArray, 56) == 1 + && sortingheck(arrayOfOneElement, 1) == 1 + && sortingheck(arrayOfZeroElement, 0) == 1; + +} + +// Function for testing sorting counting +bool correctCountSort() +{ + // Checking the operation of sorts for a random set of numbers + int arrayOfNumbersForSorting[100] = { 0 }; + for (int i = 0; i < 100; i++) + { + arrayOfNumbersForSorting[i] = rand(); + } + countSortArray(arrayOfNumbersForSorting, 100); + + // Checking the operation of sorts for an array consisting of equal numbers + int arrayOfEqualElements[40] = { 0 }; + for (int i = 0; i < 40; i++) + { + arrayOfEqualElements[i] = 144; + } + countSortArray(arrayOfEqualElements, 40); + + // Checking the operation of sorts for a sorted array + int sortedArray[56] = { 0 }; + for (int i = 0; i < 56; i++) + { + sortedArray[i] = i; + } + countSortArray(sortedArray, 56); + + // Checking the sorting operation for an array consisting of 1 element + int arrayOfOneElement[1] = { 138 }; + countSortArray(arrayOfOneElement, 1); + + // Checking for an array of 0 elements + int arrayOfZeroElement[1] = { 138 }; + countSortArray(arrayOfOneElement, 0); + + return sortingheck(arrayOfNumbersForSorting, 100) + && sortingheck(arrayOfEqualElements, 40) + && sortingheck(sortedArray, 56) + && sortingheck(arrayOfOneElement, 1) + && sortingheck(arrayOfZeroElement, 0); +} + +int main() +{ + if (!correctBubbleSort() || !correctCountSort()) + { + printf("Verification failed"); + return 0; + } + int numberOfElements = 0; + printf("Enter the number of elements in the array\n"); + const int scanfResult = scanf_s("%d", &numberOfElements); + if (scanfResult == 0 || numberOfElements <= 0) + { + printf("Input error"); + return 0; + } + int* arrayOfNumbersForSortingCount = (int*)calloc(numberOfElements, sizeof(int)); + if (arrayOfNumbersForSortingCount == NULL) + { + return -1; + } + + for (int i = 0; i < numberOfElements; i++) + { + arrayOfNumbersForSortingCount[i] = rand(); + } + int* arrayOfNumbersForSortingBubble = (int*)calloc(numberOfElements, sizeof(int)); + if (arrayOfNumbersForSortingBubble == NULL) + { + return -1; + } + for (int i = 0; i < numberOfElements; i++) + { + arrayOfNumbersForSortingBubble[i] = arrayOfNumbersForSortingCount[i]; + } + clock_t initialMomentOfTime = clock(); + countSortArray(arrayOfNumbersForSortingCount, numberOfElements); + clock_t endPointOfTime = clock(); + printf("The number of time cycles that have elapsed since the call of the function that sorts the array by counting = %d \n\n", endPointOfTime - initialMomentOfTime); + initialMomentOfTime = clock(); + bubbleSortArray(arrayOfNumbersForSortingBubble, numberOfElements); + endPointOfTime = clock(); + printf("The number of time cycles that have elapsed since the call of the function that sorts the array with a bubble = %d \n\n", endPointOfTime - initialMomentOfTime); + free(arrayOfNumbersForSortingCount); + free(arrayOfNumbersForSortingBubble); +} \ No newline at end of file diff --git "a/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj" "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj" new file mode 100644 index 0000000..faa09f6 --- /dev/null +++ "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj" @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {a2ac6b8b-943f-4b6a-8130-896b08df5092} + CountAndBubbleSort + 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/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.filters" "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.filters" new file mode 100644 index 0000000..c57d162 --- /dev/null +++ "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.user" "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.user" new file mode 100644 index 0000000..88a5509 --- /dev/null +++ "b/Homework \342\204\2262/CountAndBubbleSort/CountAndBubbleSort/CountAndBubbleSort.vcxproj.user" @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git "a/Homework \342\204\2262/Extent/Extent.sln" "b/Homework \342\204\2262/Extent/Extent.sln" new file mode 100644 index 0000000..5993001 --- /dev/null +++ "b/Homework \342\204\2262/Extent/Extent.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}") = "Extent", "Extent\Extent.vcxproj", "{8289129F-61BD-4329-BAAD-1A56B4A73635}" +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 + {8289129F-61BD-4329-BAAD-1A56B4A73635}.Debug|x64.ActiveCfg = Debug|x64 + {8289129F-61BD-4329-BAAD-1A56B4A73635}.Debug|x64.Build.0 = Debug|x64 + {8289129F-61BD-4329-BAAD-1A56B4A73635}.Debug|x86.ActiveCfg = Debug|Win32 + {8289129F-61BD-4329-BAAD-1A56B4A73635}.Debug|x86.Build.0 = Debug|Win32 + {8289129F-61BD-4329-BAAD-1A56B4A73635}.Release|x64.ActiveCfg = Release|x64 + {8289129F-61BD-4329-BAAD-1A56B4A73635}.Release|x64.Build.0 = Release|x64 + {8289129F-61BD-4329-BAAD-1A56B4A73635}.Release|x86.ActiveCfg = Release|Win32 + {8289129F-61BD-4329-BAAD-1A56B4A73635}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2B6035B2-0A18-43BE-9BF6-6AF14FFDF410} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2262/Extent/Extent/Extent.vcxproj" "b/Homework \342\204\2262/Extent/Extent/Extent.vcxproj" new file mode 100644 index 0000000..b8e014c --- /dev/null +++ "b/Homework \342\204\2262/Extent/Extent/Extent.vcxproj" @@ -0,0 +1,148 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {8289129f-61bd-4329-baad-1a56b4a73635} + Extent + 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 + Default + + + 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\2262/Extent/Extent/Extent.vcxproj.filters" "b/Homework \342\204\2262/Extent/Extent/Extent.vcxproj.filters" new file mode 100644 index 0000000..7dd0415 --- /dev/null +++ "b/Homework \342\204\2262/Extent/Extent/Extent.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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\2262/Extent/Extent/Extent.vcxproj.user" "b/Homework \342\204\2262/Extent/Extent/Extent.vcxproj.user" new file mode 100644 index 0000000..88a5509 --- /dev/null +++ "b/Homework \342\204\2262/Extent/Extent/Extent.vcxproj.user" @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git "a/Homework \342\204\2262/Extent/Extent/extent.c" "b/Homework \342\204\2262/Extent/Extent/extent.c" new file mode 100644 index 0000000..7f5b838 --- /dev/null +++ "b/Homework \342\204\2262/Extent/Extent/extent.c" @@ -0,0 +1,117 @@ +#include +#include +#include + +// function that returns the result depending on the signs of the exponent and the base of the degree (double for degrees of type 5^(-4) = 0.0016). = 0.0016). +double resultFromSign(double exponentiationResult, int basisOfDegree, int degreeIndicator) +{ + if (basisOfDegree > 0 && degreeIndicator < 0) + { + return 1 / exponentiationResult; + } + + if (basisOfDegree > 0 && degreeIndicator > 0) + { + return exponentiationResult; + } + + if (basisOfDegree < 0 && degreeIndicator > 0) + { + if (degreeIndicator % 2 != 0) + { + return -exponentiationResult; + } + + if (degreeIndicator % 2 == 0) + { + return exponentiationResult; + } + } + + if (basisOfDegree < 0 && degreeIndicator < 0) + { + if (degreeIndicator % 2 != 0) + { + return -1 / exponentiationResult; + } + + if (degreeIndicator % 2 == 0) + { + return 1 / exponentiationResult; + } + } + + if (basisOfDegree != 0 && degreeIndicator == 0) + { + return 1; + } + return 0; +} + +// exponentiation in O (log n) +double effectiveExponentiation(int basisOfDegree, int degreeIndicator) +{ + double exponentiationResult = 1; + int absoluteValueDegreeIndicator = abs(degreeIndicator); + double absoluteValueBasisOfDegree = abs(basisOfDegree); + while (absoluteValueDegreeIndicator > 0) + { + if (absoluteValueDegreeIndicator % 2 == 0) + { + absoluteValueDegreeIndicator = absoluteValueDegreeIndicator / 2; + absoluteValueBasisOfDegree *= absoluteValueBasisOfDegree; + } + else + { + absoluteValueDegreeIndicator--; + exponentiationResult *= absoluteValueBasisOfDegree; + } + } + exponentiationResult = resultFromSign(exponentiationResult, basisOfDegree, degreeIndicator); + return exponentiationResult; +} + +// exponentiation in linear time +double ineffectiveExponentiation(int basisOfDegree, int degreeIndicator) +{ + double exponentiationResult = 1; + int absoluteValueDegreeIndicator = abs(degreeIndicator); + int absoluteValueBasisOfDegree = abs(basisOfDegree); + for (int i = 1; i <= absoluteValueDegreeIndicator; i++) + { + exponentiationResult *= absoluteValueBasisOfDegree; + } + exponentiationResult = resultFromSign(exponentiationResult, basisOfDegree, degreeIndicator); + return exponentiationResult; +} + +bool testCorrectExponentiation() +{ + return effectiveExponentiation(-1, 5) == -1 && ineffectiveExponentiation(-1, 5) == -1 + && effectiveExponentiation(0, 5) == 0 && ineffectiveExponentiation(0, 5) == 0 + && effectiveExponentiation(5, 0) == 1 && ineffectiveExponentiation(5, 0) == 1 + && effectiveExponentiation(-5, -2) == 0.04 && effectiveExponentiation(2, -5) == 0.03125 + && ineffectiveExponentiation(12, 4) == 20736 && ineffectiveExponentiation(2, -4) == 0.0625; +} + +int main() +{ + if (!testCorrectExponentiation()) + { + printf("The test failed\n"); + return 0; + } + printf("Enter the degree base\n"); + int basisOfDegree = 0; + scanf_s("%d", &basisOfDegree); + printf("Enter the degree indicator\n"); + int degreeIndicator = 0; + scanf_s("%d", °reeIndicator); + if (basisOfDegree == 0 && degreeIndicator == 0) + { + printf("The expression doesn't make sense."); + return 0; + } + printf("Exponentiation in O (log n) : %.16lf\n\n", effectiveExponentiation(basisOfDegree, degreeIndicator)); + printf("Exponentiation in linear time : %.16lf\n", ineffectiveExponentiation(basisOfDegree, degreeIndicator)); +} \ No newline at end of file diff --git "a/Homework \342\204\2262/Fibonacci/Fibonacci.sln" "b/Homework \342\204\2262/Fibonacci/Fibonacci.sln" new file mode 100644 index 0000000..1232aa0 --- /dev/null +++ "b/Homework \342\204\2262/Fibonacci/Fibonacci.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}") = "Fibonacci", "Fibonacci\Fibonacci.vcxproj", "{462949E2-AB0D-4103-A82A-3277512C135D}" +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 + {462949E2-AB0D-4103-A82A-3277512C135D}.Debug|x64.ActiveCfg = Debug|x64 + {462949E2-AB0D-4103-A82A-3277512C135D}.Debug|x64.Build.0 = Debug|x64 + {462949E2-AB0D-4103-A82A-3277512C135D}.Debug|x86.ActiveCfg = Debug|Win32 + {462949E2-AB0D-4103-A82A-3277512C135D}.Debug|x86.Build.0 = Debug|Win32 + {462949E2-AB0D-4103-A82A-3277512C135D}.Release|x64.ActiveCfg = Release|x64 + {462949E2-AB0D-4103-A82A-3277512C135D}.Release|x64.Build.0 = Release|x64 + {462949E2-AB0D-4103-A82A-3277512C135D}.Release|x86.ActiveCfg = Release|Win32 + {462949E2-AB0D-4103-A82A-3277512C135D}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {74CBB9D0-7E3B-4009-AB0B-5F9EF9CFFA4B} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.c" "b/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.c" new file mode 100644 index 0000000..655a01d --- /dev/null +++ "b/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.c" @@ -0,0 +1,79 @@ +#include +#include + +int sequenceFibonacciIteration(int numberOfSequence) +{ + // checking for the correctness of the entered number + if (numberOfSequence < 0) + { + printf("Input error."); + return -1; + } + + int firstElementSequenceOfFibonacci = 1; + int secondElementSequenceOfFibonacci = 1; + int thirdElementSequenceOfFibonacci = 0; + + for (int i = 0; i < numberOfSequence - 2; i++) + { + thirdElementSequenceOfFibonacci = firstElementSequenceOfFibonacci + secondElementSequenceOfFibonacci; + firstElementSequenceOfFibonacci = secondElementSequenceOfFibonacci; + secondElementSequenceOfFibonacci = thirdElementSequenceOfFibonacci; + } + + if (numberOfSequence == 0) + { + return 0; + } + + if (numberOfSequence > 0) + { + return secondElementSequenceOfFibonacci; + } +} + +int sequenceFibonacciRecursion(int numberOfSequence) +{ + // checking for the correctness of the entered number + if (numberOfSequence < 0) + { + printf("Input error."); + exit(0); + } + + if (numberOfSequence == 1) + { + return 1; + } + + if (numberOfSequence == 0) + { + return 0; + } + + return sequenceFibonacciRecursion(numberOfSequence - 1) + sequenceFibonacciRecursion(numberOfSequence - 2); +} + +// function for checking the correctness of the program +bool testCorrectFibonacci() +{ + return sequenceFibonacciIteration(1) == 1 && sequenceFibonacciRecursion(1) == 1 + && sequenceFibonacciIteration(0) == 0 && sequenceFibonacciRecursion(0) == 0 + && sequenceFibonacciIteration(12) == 144 && sequenceFibonacciRecursion(12) == 144 + && sequenceFibonacciIteration(16) == 987 + && sequenceFibonacciRecursion(20) == 6765; +} + +int main() +{ + if (!testCorrectFibonacci()) + { + printf("Verification failed"); + return 0; + } + printf("Enter the number of the member of the Fibonacci sequence that you want to display on the screen\n"); + int numberOfSequence = 0; + scanf_s("%d", &numberOfSequence); + printf("Iterative version : %d\n", sequenceFibonacciIteration(numberOfSequence)); + printf("Recursive version : %d\n", sequenceFibonacciRecursion(numberOfSequence)); +} \ No newline at end of file diff --git "a/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj" "b/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj" new file mode 100644 index 0000000..41e4761 --- /dev/null +++ "b/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj" @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {462949e2-ab0d-4103-a82a-3277512c135d} + Fibonacci + 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/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.filters" "b/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.filters" new file mode 100644 index 0000000..dd68821 --- /dev/null +++ "b/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.user" "b/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.user" new file mode 100644 index 0000000..88a5509 --- /dev/null +++ "b/Homework \342\204\2262/Fibonacci/Fibonacci/Fibonacci.vcxproj.user" @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git "a/Homework \342\204\2262/semiQSort/semiQSort.sln" "b/Homework \342\204\2262/semiQSort/semiQSort.sln" new file mode 100644 index 0000000..de507e6 --- /dev/null +++ "b/Homework \342\204\2262/semiQSort/semiQSort.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}") = "semiQSort", "semiQSort\semiQSort.vcxproj", "{504AECC2-9812-4877-A7D8-6D3870ACDA9B}" +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 + {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Debug|x64.ActiveCfg = Debug|x64 + {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Debug|x64.Build.0 = Debug|x64 + {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Debug|x86.ActiveCfg = Debug|Win32 + {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Debug|x86.Build.0 = Debug|Win32 + {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Release|x64.ActiveCfg = Release|x64 + {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Release|x64.Build.0 = Release|x64 + {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Release|x86.ActiveCfg = Release|Win32 + {504AECC2-9812-4877-A7D8-6D3870ACDA9B}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AF819222-5F44-4372-8F2B-E48E71B4478F} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.c" "b/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.c" new file mode 100644 index 0000000..f1fe32f --- /dev/null +++ "b/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.c" @@ -0,0 +1,119 @@ +#include +#include +#include +#include + +int semiQSort(int* arrayOfNumber, int numberElementsInArray) +{ + int increment = 1; + int decrement = numberElementsInArray - 1; + + while (increment < decrement) + { + /* the second condition of the loop is not to add increment once again, because the array can already be sorted and in the + case when there are more elements than the reference less than the elements less than the reference increment will increase to countOfElementsLessFirst + 1 and only + after that, the cycle will stop, i.e. a lot of extra increments will be made*/ + while (arrayOfNumber[increment] < arrayOfNumber[0] && increment < decrement) + { + increment++; + } + while (arrayOfNumber[decrement] >= arrayOfNumber[0] && decrement > increment) + { + decrement--; + } + if (increment < decrement) + { + const int temporaryVariable = arrayOfNumber[decrement]; + arrayOfNumber[decrement] = arrayOfNumber[increment]; + arrayOfNumber[increment] = temporaryVariable; + } + increment++; + decrement--; + } + return decrement; +} + +bool sortingheck(int* arrayOfNumber, int numberOfElements, int index) +{ + for (int i = 1; i < index + 1; i++) + { + if (arrayOfNumber[i] >= arrayOfNumber[0]) + { + return false; + } + } + for (int i = index + 1; i < numberOfElements; i++) + { + if (arrayOfNumber[i] < arrayOfNumber[0]) + { + return false; + } + } + return true; +} + +bool correctSemiQSort() +{ + // Checking the operation of sorting for a random set of numbers + int arrayOfNumber[8] = {4, 7, 2, 5, 4, 8, 1, 3}; + + // Checking the sorting operation for an array consisting of equal elements + int arrayOfEqualValues[100] = {0}; + for (int i = 0; i < 100; i++) + { + arrayOfEqualValues[i] = 5; + } + + // Checking the sorting operation for a sorted array + int sortedArray[100] = {0}; + for (int i = 0; i < 100; i++) + { + sortedArray[i] = i; + } + + // Checking the sorting operation for an array consisting of a single element + int arrayOfOneElement[1] = {15}; + + int arrayOfZeroElement[1] = {0}; + + return sortingheck(arrayOfNumber, 8, semiQSort(arrayOfNumber, 8)) + && sortingheck(arrayOfEqualValues, 100, semiQSort(arrayOfEqualValues, 100)) + && sortingheck(sortedArray, 100, semiQSort(sortedArray, 100)) + && sortingheck(arrayOfOneElement, 1, semiQSort(arrayOfOneElement, 1)) + && sortingheck(arrayOfZeroElement, 0, semiQSort(arrayOfZeroElement, 0)); +} + +int main() +{ + if (!correctSemiQSort()) + { + printf("Verification failed"); + return 0; + } + printf("Enter the number of elements in the array\n"); + int numberElementsInArray = 0; + const int scanfNumberElemntInArrayResult = scanf_s("%d", &numberElementsInArray); + if (scanfNumberElemntInArrayResult == 0 || numberElementsInArray <= 0) + { + printf("Input error"); + return 0; + } + int* arrayOfNumber = (int*)calloc(numberElementsInArray, sizeof(int)); + if (arrayOfNumber == NULL) + { + return -1; + } + for (int i = 0; i < numberElementsInArray; i++) + { + // to visually verify that it works correctly, you can add rand () % n, because the first number may be the minimum + arrayOfNumber[i] = rand(); + printf(" %d", arrayOfNumber[i]); + } + printf("\n\n"); + semiQSort(arrayOfNumber, numberElementsInArray); + for (int i = 0; i < numberElementsInArray; i++) + { + printf(" %d", arrayOfNumber[i]); + } + free(arrayOfNumber); +} \ No newline at end of file diff --git "a/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj" "b/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj" new file mode 100644 index 0000000..4a64740 --- /dev/null +++ "b/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj" @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {504aecc2-9812-4877-a7d8-6d3870acda9b} + semiQSort + 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/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.filters" "b/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.filters" new file mode 100644 index 0000000..d6610d1 --- /dev/null +++ "b/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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\2262/semiQSort/semiQSort/semiQSort.vcxproj.user" "b/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.user" new file mode 100644 index 0000000..88a5509 --- /dev/null +++ "b/Homework \342\204\2262/semiQSort/semiQSort/semiQSort.vcxproj.user" @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git "a/Homework \342\204\2263/binarySearch/binarySearch.sln" "b/Homework \342\204\2263/binarySearch/binarySearch.sln" new file mode 100644 index 0000000..38643b0 --- /dev/null +++ "b/Homework \342\204\2263/binarySearch/binarySearch.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}") = "binarySearch", "binarySearch\binarySearch.vcxproj", "{31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}" +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 + {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Debug|x64.ActiveCfg = Debug|x64 + {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Debug|x64.Build.0 = Debug|x64 + {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Debug|x86.ActiveCfg = Debug|Win32 + {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Debug|x86.Build.0 = Debug|Win32 + {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Release|x64.ActiveCfg = Release|x64 + {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Release|x64.Build.0 = Release|x64 + {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Release|x86.ActiveCfg = Release|Win32 + {31D8B8EA-29AB-4F6D-AEBB-80D1B64B2A9C}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F7D7DBDD-3E67-455A-8DB4-0498CC6E6954} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2263/binarySearch/binarySearch/binary.h" "b/Homework \342\204\2263/binarySearch/binarySearch/binary.h" new file mode 100644 index 0000000..c23afd1 --- /dev/null +++ "b/Homework \342\204\2263/binarySearch/binarySearch/binary.h" @@ -0,0 +1,8 @@ +#pragma once +#include + +// binary search function +int binarySearch(int* arrayOfNumber, int numberOfElements, int requiredNumber); + +// check if binary search works +bool testCorrectBinarySearch(); diff --git "a/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.c" "b/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.c" new file mode 100644 index 0000000..e181569 --- /dev/null +++ "b/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.c" @@ -0,0 +1,61 @@ +#include "binary.h" +#include + +// binary search function +int binarySearch(int* arrayOfNumber, int numberOfElements, int requiredNumber) +{ + int leftBorderOfTheArray = 0; + int rightBorderOfTheArray = numberOfElements - 1; + while (leftBorderOfTheArray <= rightBorderOfTheArray) + { + //this form of recording is needed in order to avoid overflow + const int middleElementIndex = leftBorderOfTheArray + (rightBorderOfTheArray - leftBorderOfTheArray) / 2; + if (arrayOfNumber[middleElementIndex] < requiredNumber) + { + leftBorderOfTheArray = middleElementIndex + 1; + } + if (arrayOfNumber[middleElementIndex] > requiredNumber) + { + rightBorderOfTheArray = middleElementIndex - 1; + } + if (arrayOfNumber[middleElementIndex] == requiredNumber) + { + return middleElementIndex; + } + } + return -1; +} + +// check if binary search works +bool testCorrectBinarySearch() +{ + // test for a random set of numbers + int arrayofNumber[10] = { 0, 1, 4, 7, 8, 9, 10, 123, 132, 134 }; + + // test for overflow + int arrayOfLargeNumbers[10] = { 2147483630, 2147483631, 2147483632, 2147483633, 2147483634, 2147483635, 2147483636, 2147483637, 2147483638, 2147483639 }; + + // find the first and last element + int arrayToFindTheFirstAndLastElement[100] = { 0 }; + for (int i = 0; i < 100; i++) + { + arrayToFindTheFirstAndLastElement[i] = i; + } + + // testForEmptyArray + int emptyArray[1] = { 0 }; + + // search for a nonexistent element + int arrayOfRandomNumbers[1000] = { 0 }; + for (int i = 0; i < 1000; i++) + { + arrayOfRandomNumbers[i] = rand() % 226; + } + + return binarySearch(arrayofNumber, 10, 134) == 9 + && binarySearch(arrayOfLargeNumbers, 10, 2147483631) == 1 + && binarySearch(emptyArray, 0, 0) == -1 + && binarySearch(arrayToFindTheFirstAndLastElement, 100, 0) == 0 + && binarySearch(arrayToFindTheFirstAndLastElement, 100, 99) == 99 + && binarySearch(arrayOfRandomNumbers, 1000, 227) == -1; +} \ No newline at end of file diff --git "a/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj" "b/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj" new file mode 100644 index 0000000..5ed6f94 --- /dev/null +++ "b/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj" @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {31d8b8ea-29ab-4f6d-aebb-80d1b64b2a9c} + binarySearch + 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/Tree/Tree/Tree.vcxproj.filters "b/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj.filters" similarity index 87% rename from Tree/Tree/Tree.vcxproj.filters rename to "Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj.filters" index b5b3253..aeaa7ab 100644 --- a/Tree/Tree/Tree.vcxproj.filters +++ "b/Homework \342\204\2263/binarySearch/binarySearch/binarySearch.vcxproj.filters" @@ -15,21 +15,21 @@ - + Исходные файлы - + Исходные файлы - + Исходные файлы - + Файлы заголовков - + Файлы заголовков diff --git "a/Homework \342\204\2263/binarySearch/binarySearch/main.c" "b/Homework \342\204\2263/binarySearch/binarySearch/main.c" new file mode 100644 index 0000000..df065a9 --- /dev/null +++ "b/Homework \342\204\2263/binarySearch/binarySearch/main.c" @@ -0,0 +1,36 @@ +#include +#include +#include "binary.h" +#include "qsort.h" + +int main() +{ + if (!testCorrectBinarySearch() || !testCorrectQSort()) + { + printf("error"); + return 0; + } + int numberOfElements = 0; + printf("Enter the number of elements in the array\n"); + scanf_s("%d", &numberOfElements); + int* arrayOfNumber = (int*)calloc(numberOfElements, sizeof(int)); + if (arrayOfNumber == NULL) + { + return -1; + } + for (int i = 0; i < numberOfElements; i++) + { + arrayOfNumber[i] = rand(); + } + smartQSort(arrayOfNumber, 0, numberOfElements - 1); + printf("Enter the number of numbers that you need to enter to search in the array\n"); + int numberOfRequiredNumbers = 0; + scanf_s("%d", &numberOfRequiredNumbers); + printf("if (- 1) : then the number is not in the array\n"); + for (int i = 0; i < numberOfRequiredNumbers; i++) + { + const int temporary = rand(); + printf("the number %d : % d array number\n", temporary, binarySearch(arrayOfNumber, numberOfElements, temporary)); + } + free(arrayOfNumber); +} \ No newline at end of file diff --git "a/Homework \342\204\2263/binarySearch/binarySearch/qsort.c" "b/Homework \342\204\2263/binarySearch/binarySearch/qsort.c" new file mode 100644 index 0000000..530c255 --- /dev/null +++ "b/Homework \342\204\2263/binarySearch/binarySearch/qsort.c" @@ -0,0 +1,107 @@ +#include "qsort.h" + +// function for sorting by inserts +void sortByInserts(int* arrayOfNumber, int initialElement, int endElement) +{ + for (int i = initialElement + 1; i <= endElement; i++) + { + int elementToTheLeftOfKey = i - 1; + const int keyArray = arrayOfNumber[i]; + while (arrayOfNumber[elementToTheLeftOfKey] > keyArray && elementToTheLeftOfKey >= initialElement) + { + arrayOfNumber[elementToTheLeftOfKey + 1] = arrayOfNumber[elementToTheLeftOfKey]; + elementToTheLeftOfKey--; + } + arrayOfNumber[elementToTheLeftOfKey + 1] = keyArray; + } +} + +// function for sorting an array +void smartQSort(int* arrayOfNumber, int initialElement, int endElement) +{ + int leftBorderOfSegment = initialElement; + int rightBorderOfSegment = endElement; + int supportElement = 0; + if (arrayOfNumber[leftBorderOfSegment] <= arrayOfNumber[leftBorderOfSegment + 1]) + { + supportElement = arrayOfNumber[leftBorderOfSegment + 1]; + } + else + { + supportElement = arrayOfNumber[leftBorderOfSegment]; + } + if (endElement - initialElement + 1 >= 10) + { + while (leftBorderOfSegment < rightBorderOfSegment) + { + while (arrayOfNumber[leftBorderOfSegment] < supportElement && leftBorderOfSegment <= rightBorderOfSegment) + { + leftBorderOfSegment++; + } + while (arrayOfNumber[rightBorderOfSegment] > supportElement && rightBorderOfSegment >= leftBorderOfSegment) + { + rightBorderOfSegment--; + } + if (leftBorderOfSegment < rightBorderOfSegment) + { + const int temporaryVariable = arrayOfNumber[rightBorderOfSegment]; + arrayOfNumber[rightBorderOfSegment] = arrayOfNumber[leftBorderOfSegment]; + arrayOfNumber[leftBorderOfSegment] = temporaryVariable; + leftBorderOfSegment++; + rightBorderOfSegment--; + } + } + smartQSort(arrayOfNumber, initialElement, rightBorderOfSegment); + smartQSort(arrayOfNumber, leftBorderOfSegment, endElement); + } + else + { + sortByInserts(arrayOfNumber, initialElement, endElement); + } +} + +// function for checking the sorting of an array +bool sortingCheck(int* arrayOfNumber, int numberOfElements) +{ + for (int i = 0; i < numberOfElements - 1; i++) + { + if (arrayOfNumber[i] > arrayOfNumber[i + 1]) + { + return false; + } + } + return true; +} + +// function for testing sorting QSort +bool testCorrectQSort() +{ + // Array of random numbers + int arrayOfNumber[10] = { 9, 7, 8, 6, 3, 1, 7, 0, 3, 2 }; + smartQSort(arrayOfNumber, 0, 9); + + // Array of equal numbers + int arrayOfEqualValues[100] = { 0 }; + for (int i = 0; i < 100; i++) + { + arrayOfEqualValues[i] = 12; + } + smartQSort(arrayOfEqualValues, 0, 99); + + // Sorted array + int sortedArray[100] = { 0 }; + for (int i = 0; i < 100; i++) + { + sortedArray[i] = i; + } + smartQSort(sortedArray, 0, 99); + + // Array of one element + int arrayOfOneElement[1] = { 109 }; + smartQSort(arrayOfEqualValues, 0, 0); + + return sortingCheck(arrayOfNumber, 10) + && sortingCheck(arrayOfEqualValues, 100) + && sortingCheck(sortedArray, 100) + && sortingCheck(arrayOfOneElement, 1); +} \ No newline at end of file diff --git "a/Homework \342\204\2263/binarySearch/binarySearch/qsort.h" "b/Homework \342\204\2263/binarySearch/binarySearch/qsort.h" new file mode 100644 index 0000000..28a2257 --- /dev/null +++ "b/Homework \342\204\2263/binarySearch/binarySearch/qsort.h" @@ -0,0 +1,15 @@ +#pragma once +#include + +// function for sorting an array +void smartQSort(int* arrayOfNumber, int initialElement, int endElement); + +// function for checking the sorting of an array +bool sortingCheck(int* arrayOfNumber, int numberOfElements); + +// function for testing sorting QSort +bool testCorrectQSort(); + +// function for sorting by inserts +void sortByInserts(int* arrayOfNumber, int initialElement, int endElement); + diff --git "a/Homework \342\204\2263/quickSort/quickSort.sln" "b/Homework \342\204\2263/quickSort/quickSort.sln" new file mode 100644 index 0000000..8e712d4 --- /dev/null +++ "b/Homework \342\204\2263/quickSort/quickSort.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}") = "quickSort", "quickSort\quickSort.vcxproj", "{16F21A94-4C1F-497E-9830-A36A16AC1481}" +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 + {16F21A94-4C1F-497E-9830-A36A16AC1481}.Debug|x64.ActiveCfg = Debug|x64 + {16F21A94-4C1F-497E-9830-A36A16AC1481}.Debug|x64.Build.0 = Debug|x64 + {16F21A94-4C1F-497E-9830-A36A16AC1481}.Debug|x86.ActiveCfg = Debug|Win32 + {16F21A94-4C1F-497E-9830-A36A16AC1481}.Debug|x86.Build.0 = Debug|Win32 + {16F21A94-4C1F-497E-9830-A36A16AC1481}.Release|x64.ActiveCfg = Release|x64 + {16F21A94-4C1F-497E-9830-A36A16AC1481}.Release|x64.Build.0 = Release|x64 + {16F21A94-4C1F-497E-9830-A36A16AC1481}.Release|x86.ActiveCfg = Release|Win32 + {16F21A94-4C1F-497E-9830-A36A16AC1481}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C1AE2CF6-53F4-44C0-B515-54C3158A1CAE} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj" "b/Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj" new file mode 100644 index 0000000..e3a55d1 --- /dev/null +++ "b/Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj" @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {16f21a94-4c1f-497e-9830-a36a16ac1481} + quickSort + 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/Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj.filters" "b/Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj.filters" new file mode 100644 index 0000000..8b192d6 --- /dev/null +++ "b/Homework \342\204\2263/quickSort/quickSort/quickSort.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {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\2263/quickSort/quickSort/quicksort.c" "b/Homework \342\204\2263/quickSort/quickSort/quicksort.c" new file mode 100644 index 0000000..d9dafb9 --- /dev/null +++ "b/Homework \342\204\2263/quickSort/quickSort/quicksort.c" @@ -0,0 +1,136 @@ +#include +#include +#include +#include + +void sortByInserts(int* arrayOfNumber, int initialElement, int endElement) +{ + for (int i = initialElement + 1; i <= endElement; i++) + { + int elementToTheLeftOfKey = i - 1; + const int keyArray = arrayOfNumber[i]; + while (arrayOfNumber[elementToTheLeftOfKey] > keyArray && elementToTheLeftOfKey >= initialElement) + { + arrayOfNumber[elementToTheLeftOfKey + 1] = arrayOfNumber[elementToTheLeftOfKey]; + elementToTheLeftOfKey--; + } + arrayOfNumber[elementToTheLeftOfKey + 1] = keyArray; + } +} + +void smartQSort(int* arrayOfNumber, int initialElement, int endElement) +{ + int leftBorderOfSegment = initialElement; + int rightBorderOfSegment = endElement; + int supportElement = 0; + if (arrayOfNumber[leftBorderOfSegment] <= arrayOfNumber[leftBorderOfSegment + 1]) + { + supportElement = arrayOfNumber[leftBorderOfSegment + 1]; + } + else + { + supportElement = arrayOfNumber[leftBorderOfSegment]; + } + if (endElement - initialElement + 1 >= 10) + { + while (leftBorderOfSegment < rightBorderOfSegment) + { + while (arrayOfNumber[leftBorderOfSegment] < supportElement && leftBorderOfSegment <= rightBorderOfSegment) + { + leftBorderOfSegment++; + } + while (arrayOfNumber[rightBorderOfSegment] > supportElement && rightBorderOfSegment >= leftBorderOfSegment) + { + rightBorderOfSegment--; + } + if (leftBorderOfSegment < rightBorderOfSegment) + { + const int temporaryVariable = arrayOfNumber[rightBorderOfSegment]; + arrayOfNumber[rightBorderOfSegment] = arrayOfNumber[leftBorderOfSegment]; + arrayOfNumber[leftBorderOfSegment] = temporaryVariable; + leftBorderOfSegment++; + rightBorderOfSegment--; + } + } + smartQSort(arrayOfNumber, initialElement, rightBorderOfSegment); + smartQSort(arrayOfNumber, leftBorderOfSegment, endElement); + } + else + { + sortByInserts(arrayOfNumber, initialElement, endElement); + } +} + +// Function for checking the sorting of an array +bool sortingCheck(int* arrayOfNumber, int numberOfElements) +{ + for (int i = 0; i < numberOfElements - 1; i++) + { + if (arrayOfNumber[i] > arrayOfNumber[i + 1]) + { + return false; + } + } + return true; +} + +// Function for testing QSort sorting +bool testCorrectQSort() +{ + // An array of random numbers + int arrayOfNumber[10] = { 9, 7, 8, 6, 3, 1, 7, 0, 3, 2 }; + smartQSort(arrayOfNumber, 0, 9); + + // An array of equal numbers + int arrayOfEqualValues[100] = { 0 }; + for (int i = 0; i < 100; i++) + { + arrayOfEqualValues[i] = 12; + } + smartQSort(arrayOfEqualValues, 0, 99); + + // Sorted array + int sortedArray[100] = { 0 }; + for (int i = 0; i < 100; i++) + { + sortedArray[i] = i; + } + smartQSort(sortedArray, 0, 99); + + // An array of one element + int arrayOfOneElement[1] = { 109 }; + smartQSort(arrayOfEqualValues, 0, 0); + + return sortingCheck(arrayOfNumber, 10) + && sortingCheck(arrayOfEqualValues, 100) + && sortingCheck(sortedArray, 100) + && sortingCheck(arrayOfOneElement, 1); +} + +int main() +{ + if (!testCorrectQSort()) + { + printf(" error"); + return 0; + } + int numberOfElements = 0; + printf("Enter the number of elements in the array\n"); + scanf_s("%d", &numberOfElements); + int* arrayOfNumber = (int*)calloc(numberOfElements, sizeof(int)); + if (arrayOfNumber == NULL) + { + return -1; + } + // % 14 for clear output to the screen + for (int i = 0; i < numberOfElements; i++) + { + arrayOfNumber[i] = rand() % 14; + } + smartQSort(arrayOfNumber, 0, numberOfElements - 1); + for (int i = 0; i < numberOfElements; i++) + { + printf(" %d", arrayOfNumber[i]); + } + free(arrayOfNumber); +} \ No newline at end of file diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement.sln" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement.sln" new file mode 100644 index 0000000..a4e9d28 --- /dev/null +++ "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement.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}") = "theMostCommonElement", "theMostCommonElement\theMostCommonElement.vcxproj", "{EF7D2016-E0AC-4058-B9D6-C845C565D6BB}" +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 + {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Debug|x64.ActiveCfg = Debug|x64 + {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Debug|x64.Build.0 = Debug|x64 + {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Debug|x86.ActiveCfg = Debug|Win32 + {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Debug|x86.Build.0 = Debug|Win32 + {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Release|x64.ActiveCfg = Release|x64 + {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Release|x64.Build.0 = Release|x64 + {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Release|x86.ActiveCfg = Release|Win32 + {EF7D2016-E0AC-4058-B9D6-C845C565D6BB}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4CDB3EC5-EBAA-41F9-A341-71F57200891A} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.c" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.c" new file mode 100644 index 0000000..c9b8be2 --- /dev/null +++ "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.c" @@ -0,0 +1,33 @@ +#include "TheMostCommonElement.h" + +// function to find the most frequent element in an array +int searchMostCommonElementInArray(int* arrayOfNumber, int numberOfElements) +{ + int currentElement = arrayOfNumber[0]; + int counterTheCurrentElement = 1; + int counterThePreviousElement = 1; + int savingTheCurrentElement = currentElement; + for (int i = 1; i < numberOfElements; i++) + { + if (arrayOfNumber[i] == currentElement) + { + counterTheCurrentElement++; + } + else + { + if (counterTheCurrentElement > counterThePreviousElement) + { + counterThePreviousElement = counterTheCurrentElement; + savingTheCurrentElement = currentElement; + } + currentElement = arrayOfNumber[i]; + counterTheCurrentElement = 1; + } + } + // condition for the last element (if the last element was repeated, then else from the for loop will not work for it) + if (counterThePreviousElement < counterTheCurrentElement) + { + savingTheCurrentElement = currentElement; + } + return savingTheCurrentElement; +} \ No newline at end of file diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.h" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.h" new file mode 100644 index 0000000..14b066b --- /dev/null +++ "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/TheMostCommonElement.h" @@ -0,0 +1,4 @@ +#pragma once + +// function to find the most frequent element in an array +int searchMostCommonElementInArray(int* arrayOfNumber, int numberOfElements); \ No newline at end of file diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/main.c" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/main.c" new file mode 100644 index 0000000..2210d3f --- /dev/null +++ "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/main.c" @@ -0,0 +1,28 @@ +#include +#include +#include "theMostCommonElement.h" +#include "qsort.h" +#include "test.h" + +int main() +{ + if (!testCorrectQSort() || !testSearchMostCommonElement()) + { + printf("test failed"); + return -1; + } + int numberOfElements = 0; + printf("enter the number of elements in the array\n"); + scanf_s("%d", &numberOfElements); + int* arrayOfNumber = (int*)calloc(numberOfElements, sizeof(int)); + if (arrayOfNumber == NULL) + { + return -1; + } + for (int i = 0; i < numberOfElements; i++) + { + arrayOfNumber[i] = rand() % 11; + } + QSort(arrayOfNumber, numberOfElements); + printf("the most common element in the array : %d\n", searchMostCommonElementInArray(arrayOfNumber, numberOfElements)); +} \ No newline at end of file diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.c" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.c" new file mode 100644 index 0000000..ba7cbfc --- /dev/null +++ "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.c" @@ -0,0 +1,64 @@ +#include "qsort.h" + +void QSort(int* arrayOfNumber, int numberOfElement) +{ + smartQSort(arrayOfNumber, 0, numberOfElement - 1); +} +// function for sorting by inserts +void sortByInserts(int* arrayOfNumber, int initialElement, int endElement) +{ + for (int i = initialElement + 1; i <= endElement; i++) + { + int elementToTheLeftOfKey = i - 1; + const int keyArray = arrayOfNumber[i]; + while (arrayOfNumber[elementToTheLeftOfKey] > keyArray && elementToTheLeftOfKey >= initialElement) + { + arrayOfNumber[elementToTheLeftOfKey + 1] = arrayOfNumber[elementToTheLeftOfKey]; + elementToTheLeftOfKey--; + } + arrayOfNumber[elementToTheLeftOfKey + 1] = keyArray; + } +} + +// function for sorting an array +int smartQSort(int* arrayOfNumber, int initialElement, int endElement) +{ + if (endElement - initialElement + 1 < 10) + { + sortByInserts(arrayOfNumber, initialElement, endElement); + return 0; + } + int leftBorderOfSegment = initialElement; + int rightBorderOfSegment = endElement; + int supportElement = 0; + if (arrayOfNumber[leftBorderOfSegment] <= arrayOfNumber[leftBorderOfSegment + 1]) + { + supportElement = arrayOfNumber[leftBorderOfSegment + 1]; + } + else + { + supportElement = arrayOfNumber[leftBorderOfSegment]; + } + while (leftBorderOfSegment < rightBorderOfSegment) + { + while (arrayOfNumber[leftBorderOfSegment] < supportElement && leftBorderOfSegment <= rightBorderOfSegment) + { + leftBorderOfSegment++; + } + while (arrayOfNumber[rightBorderOfSegment] > supportElement && rightBorderOfSegment >= leftBorderOfSegment) + { + rightBorderOfSegment--; + } + if (leftBorderOfSegment < rightBorderOfSegment) + { + const int temporaryVariable = arrayOfNumber[rightBorderOfSegment]; + arrayOfNumber[rightBorderOfSegment] = arrayOfNumber[leftBorderOfSegment]; + arrayOfNumber[leftBorderOfSegment] = temporaryVariable; + leftBorderOfSegment++; + rightBorderOfSegment--; + } + } + smartQSort(arrayOfNumber, initialElement, rightBorderOfSegment); + smartQSort(arrayOfNumber, leftBorderOfSegment, endElement); + return 0; +} \ No newline at end of file diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.h" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.h" new file mode 100644 index 0000000..32bf1ac --- /dev/null +++ "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/qsort.h" @@ -0,0 +1,4 @@ +#pragma once + +// function for sorting an array +void QSort(int* arrayOfNumber, int numberOfElements); diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/test.h" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/test.h" new file mode 100644 index 0000000..06fcb19 --- /dev/null +++ "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/test.h" @@ -0,0 +1,8 @@ +#pragma once +#include + +// function for testing sorting QSort +bool testCorrectQSort(); + +// test for function searchMostCommonElementInArray +bool testSearchMostCommonElement(); diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/tests.c" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/tests.c" new file mode 100644 index 0000000..5a14692 --- /dev/null +++ "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/tests.c" @@ -0,0 +1,70 @@ +#include "test.h" +#include "qsort.h" +#include "theMostCommonElement.h" + +// function for checking the sorting of an array +bool sortingCheck(int* arrayOfNumber, int numberOfElements) +{ + for (int i = 0; i < numberOfElements - 1; i++) + { + if (arrayOfNumber[i] > arrayOfNumber[i + 1]) + { + return false; + } + } + return true; +} + +// function for testing sorting QSort +bool testCorrectQSort() +{ + // Array of random numbers + int arrayOfNumber[10] = { 9, 7, 8, 6, 3, 1, 7, 0, 3, 2 }; + QSort(arrayOfNumber, 10); + + // Array of equal numbers + int arrayOfEqualValues[100] = { 0 }; + for (int i = 0; i < 100; i++) + { + arrayOfEqualValues[i] = 12; + } + QSort(arrayOfEqualValues, 100); + + // Sorted array + int sortedArray[100] = { 0 }; + for (int i = 0; i < 100; i++) + { + sortedArray[i] = i; + } + QSort(sortedArray, 100); + + // Array of one element + int arrayOfOneElement[1] = { 109 }; + QSort(arrayOfEqualValues, 1); + + return sortingCheck(arrayOfNumber, 10) + && sortingCheck(arrayOfEqualValues, 100) + && sortingCheck(sortedArray, 100) + && sortingCheck(arrayOfOneElement, 1); +} + +// test for function searchMostCommonElementInArray +bool testSearchMostCommonElement() +{ + // Checking for a random set of numbers + int arrayOfRandonNumbers[15] = { 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 6, 8, 9, 12, 13 }; + + // checking for an array of a single number + int arrayOfOneElement[1] = { 12 }; + + // checking for an array of equal number + int arrayOfEqualNumbers[8] = { 1, 1, 1, 1, 1, 1, 1, 1 }; + + // check for an array of different number + int arrayOfDifferentNumbers[15] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; + + return searchMostCommonElementInArray(arrayOfRandonNumbers, 15) == 3 + && searchMostCommonElementInArray(arrayOfOneElement, 1) == 12 + && searchMostCommonElementInArray(arrayOfEqualNumbers, 8) == 1 + && searchMostCommonElementInArray(arrayOfDifferentNumbers, 15) == 1; +} \ No newline at end of file diff --git "a/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj" new file mode 100644 index 0000000..d621f34 --- /dev/null +++ "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj" @@ -0,0 +1,155 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {ef7d2016-e0ac-4058-b9d6-c845c565d6bb} + theMostCommonElement + 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/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj.filters" "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj.filters" new file mode 100644 index 0000000..e6a7184 --- /dev/null +++ "b/Homework \342\204\2263/theMostCommonElement/theMostCommonElement/theMostCommonElement.vcxproj.filters" @@ -0,0 +1,42 @@ + + + + + {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\2264/Phonebook/Phonebook.sln" "b/Homework \342\204\2264/Phonebook/Phonebook.sln" new file mode 100644 index 0000000..1f924d5 --- /dev/null +++ "b/Homework \342\204\2264/Phonebook/Phonebook.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}") = "Phonebook", "Phonebook\Phonebook.vcxproj", "{65870562-A022-4E69-83E5-D43FD4B796E2}" +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 + {65870562-A022-4E69-83E5-D43FD4B796E2}.Debug|x64.ActiveCfg = Debug|x64 + {65870562-A022-4E69-83E5-D43FD4B796E2}.Debug|x64.Build.0 = Debug|x64 + {65870562-A022-4E69-83E5-D43FD4B796E2}.Debug|x86.ActiveCfg = Debug|Win32 + {65870562-A022-4E69-83E5-D43FD4B796E2}.Debug|x86.Build.0 = Debug|Win32 + {65870562-A022-4E69-83E5-D43FD4B796E2}.Release|x64.ActiveCfg = Release|x64 + {65870562-A022-4E69-83E5-D43FD4B796E2}.Release|x64.Build.0 = Release|x64 + {65870562-A022-4E69-83E5-D43FD4B796E2}.Release|x86.ActiveCfg = Release|Win32 + {65870562-A022-4E69-83E5-D43FD4B796E2}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F6FADCAE-DF15-48D7-B221-EFC0510BD591} + EndGlobalSection +EndGlobal diff --git a/Tree/Tree/Tree.vcxproj "b/Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj" similarity index 92% rename from Tree/Tree/Tree.vcxproj rename to "Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj" index 1f66300..58566a5 100644 --- a/Tree/Tree/Tree.vcxproj +++ "b/Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj" @@ -21,8 +21,8 @@ 16.0 Win32Proj - {1b08b554-064d-4a2d-a418-3c73ff3d4652} - Tree + {65870562-a022-4e69-83e5-d43fd4b796e2} + Phonebook 10.0 @@ -86,7 +86,7 @@ Level3 true - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CONSOLE;%(PreprocessorDefinitions) true @@ -114,7 +114,7 @@ Level3 true - _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true @@ -139,13 +139,13 @@ - - - + + + - - + + diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj.filters" "b/Homework \342\204\2264/Phonebook/Phonebook/Phonebook.vcxproj.filters" new file mode 100644 index 0000000..8d00e84 --- /dev/null +++ "b/Homework \342\204\2264/Phonebook/Phonebook/Phonebook.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\2264/Phonebook/Phonebook/main.c" "b/Homework \342\204\2264/Phonebook/Phonebook/main.c" new file mode 100644 index 0000000..c63f313 --- /dev/null +++ "b/Homework \342\204\2264/Phonebook/Phonebook/main.c" @@ -0,0 +1,128 @@ +#include "phoneBook.h" +#include "tests.h" +#include +#include + +int main() +{ + setlocale(LC_ALL, "rus"); + if (!testFunctionsWorkingWithFile()) + { + printf(" "); + return -1; + } + setlocale(LC_ALL, "rus"); + printf("0 - \n"); + printf("1 - ( )\n"); + printf("2 - \n"); + printf("3 - \n"); + printf("4 - \n"); + printf("5 - \n"); + Phonebook array[100] = {0}; + int number = 1; + int numberOfRecords = readPhonebook(array, "phoneNumber.txt"); + while (number != 0) + { + printf(" ?\n"); + while (scanf("%d", &number) == 0) + { + printf(", 0 5\n"); + while (getchar() != '\n') + { + continue; + } + } + switch (number) + { + case 0: + { + return 0; + } + case 1: + { + printf(" \n"); + char name[20] = {'\0'}; + if (scanf("%s", name) == 0) + { + printf(" \n"); + break; + } + printf(" \n"); + char phoneNumber[20] = {'\0'}; + if (scanf("%s", phoneNumber) == 0) + { + printf(" \n"); + break; + } + const int addAnEntryResult = addAnEntry(array, &numberOfRecords, name, phoneNumber); + if (addAnEntryResult == -1) + { + printf(" : 100 "); + } + break; + } + case 2: + { + outputAllEntries(array, numberOfRecords); + break; + } + case 3: + { + char name[20] = {'\0'}; + printf(" \n"); + if (scanf("%s", name) == 0) + { + printf(" \n"); + break; + } + const char* findNumberByNameResult = findNumberByName(array, name, numberOfRecords); + if (findNumberByNameResult == NULL) + { + printf(" \n"); + } + else + { + printf("%s\n", findNumberByNameResult); + } + break; + } + case 4: + { + char phoneNumber[20] = { '\0' }; + printf(" \n"); + if (scanf("%s", phoneNumber) == 0) + { + printf(" \n"); + break; + } + const char *findNameByNumberResult = findNameByNumber(array, phoneNumber, numberOfRecords); + if (findNameByNumberResult == NULL) + { + printf(" \n"); + } + else + { + printf("%s\n", findNameByNumberResult); + } + break; + } + case 5: + { + if (saveTheChanges(array, numberOfRecords) == 0) + { + printf("\n"); + } + else + { + printf(" \n"); + } + break; + } + default: + { + printf(", 0 5\n"); + break; + } + } + } +} diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/phoneBook.c" "b/Homework \342\204\2264/Phonebook/Phonebook/phoneBook.c" new file mode 100644 index 0000000..116d6ba --- /dev/null +++ "b/Homework \342\204\2264/Phonebook/Phonebook/phoneBook.c" @@ -0,0 +1,90 @@ +#include "phoneBook.h" +#include +#include + +int readPhonebook(Phonebook* array, const char *fileName) +{ + FILE* file = fopen(fileName, "r"); + if (file == NULL) + { + return -1; + } + int numberOfRecords = 0; + while (!feof(file)) + { + if (fscanf(file, "%s", array[numberOfRecords].name) != EOF); + { + const int fscanfResult = fscanf(file, "%s", &array[numberOfRecords].number); + if (fscanfResult == 0) + { + break; + } + numberOfRecords++; + } + } + fclose(file); + return numberOfRecords - 1; +} + +int addAnEntry(Phonebook* array, int* numberOfRecords, const char* name, const char* phoneNumber) +{ + if (*numberOfRecords >= 100) + { + return -1; + } + (*numberOfRecords)++; + strncpy(array[*numberOfRecords].name, name, 20); + strncpy(array[*numberOfRecords].number, phoneNumber, 20); + return 1; +} + +char* findNameByNumber(Phonebook* array, const char* number, int numberOfRecords) +{ + for (int i = 0; i <= numberOfRecords; i++) + { + if (strcmp(array[i].number, number) == 0) + { + return array[i].name; + } + } + return NULL; +} + +int saveTheChanges(Phonebook* array, int numberOfRecords) +{ + FILE* file = fopen("phoneNumber.txt", "w"); + if (file == NULL) + { + return -1; + } + for (int i = 0; i <= numberOfRecords; i++) + { + if (i > 0) + { + fprintf(file, "\n"); + } + fprintf(file, "%s %s", array[i].name, array[i].number); + } + fclose(file); + return 0; +} + +char* findNumberByName(Phonebook* array, const char* name, int numberOfRecords) +{ + for (int i = 0; i <= numberOfRecords; i++) + { + if (strcmp(array[i].name, name) == 0) + { + return array[i].number; + } + } + return NULL; +} + +void outputAllEntries(Phonebook* array, int numberOfRecords) +{ + for (int i = 0; i <= numberOfRecords; i++) + { + printf("%s %s\n", array[i].name, array[i].number); + } +} diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/phoneBook.h" "b/Homework \342\204\2264/Phonebook/Phonebook/phoneBook.h" new file mode 100644 index 0000000..6213c96 --- /dev/null +++ "b/Homework \342\204\2264/Phonebook/Phonebook/phoneBook.h" @@ -0,0 +1,27 @@ +#pragma once + +// Phonebook structure for storing names and phone numbers +typedef struct +{ + char number[20]; + char name[20]; +} Phonebook; + +// Function for adding an entry to the database of numbers +int addAnEntry(Phonebook* array, int* numberOfRecords, const char* name, const char* phoneNumber); + +// Function for finding a name by phone number +char* findNameByNumber(Phonebook* array, const char* number, int numberOfRecords); + +// Function for finding a phone number by name +char* findNumberByName(Phonebook* array, const char* name, int numberOfRecords); + +// Function for displaying records on the screen +void outputAllEntries(Phonebook* array, int numberOfRecords); + +// Function for filling the phone book returns the number of entries minus one(since the count starts from 0) +int readPhonebook(Phonebook* array, const char* fileName); + +// Function for saving changes +int saveTheChanges(Phonebook* array, int numberOfRecords); + diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/phoneNumber.txt" "b/Homework \342\204\2264/Phonebook/Phonebook/phoneNumber.txt" new file mode 100644 index 0000000..c272978 --- /dev/null +++ "b/Homework \342\204\2264/Phonebook/Phonebook/phoneNumber.txt" @@ -0,0 +1,19 @@ +Ivan 89624561234 +Athanasius 234456748 +Georgy 675482949 +Alexander 3645783 +Mahmed 98456232 +Murat 12845637 +Artem 35809124 +Peter 134754843 +Matway 9045673737 +Boris 89623457 +Nikolay 234567 +Oleg 5678904 +Roman 890754345 +Pavel 4567890 +Andrey 56789000 +Nikita 44567890 +Maxim 12312312 +Anna 23453123 +Olga 12365568 \ No newline at end of file diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/test1.txt" "b/Homework \342\204\2264/Phonebook/Phonebook/test1.txt" new file mode 100644 index 0000000..f6f117a --- /dev/null +++ "b/Homework \342\204\2264/Phonebook/Phonebook/test1.txt" @@ -0,0 +1,4 @@ +Alex 5642345 +John 5432356 +James 90812345 +Qwerty 896751 \ No newline at end of file diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/tests.c" "b/Homework \342\204\2264/Phonebook/Phonebook/tests.c" new file mode 100644 index 0000000..4fa77fe --- /dev/null +++ "b/Homework \342\204\2264/Phonebook/Phonebook/tests.c" @@ -0,0 +1,34 @@ +#include "tests.h" +#include "phoneBook.h" +#include +#include + +bool testFunctionsWorkingWithFile() +{ + Phonebook arrayForTest[4] = {'\0'}; + FILE* file = fopen("test1.txt", "r"); + if (file == NULL) + { + return -1; + } + for (int i = 0; i < 4; i++) + { + if (fscanf(file, "%s", arrayForTest[i].name) != EOF); + { + const int fscanfResult = fscanf(file, "%s", &arrayForTest[i].number); + if (fscanfResult == 0) + { + break; + } + } + } + fclose(file); + + return strcmp("Alex", findNameByNumber(arrayForTest, "5642345", 4)) == 0 + && strcmp("John", findNameByNumber(arrayForTest, "5432356", 4)) == 0 + && strcmp("James", findNameByNumber(arrayForTest, "90812345", 4)) == 0 + && strcmp("5642345", findNumberByName(arrayForTest, "Alex", 4)) == 0 + && strcmp("5432356", findNumberByName(arrayForTest, "John", 4)) == 0 + && strcmp("90812345", findNumberByName(arrayForTest, "James", 4)) == 0 + && readPhonebook(arrayForTest, "test1.txt") == 3; +} diff --git "a/Homework \342\204\2264/Phonebook/Phonebook/tests.h" "b/Homework \342\204\2264/Phonebook/Phonebook/tests.h" new file mode 100644 index 0000000..46df35a --- /dev/null +++ "b/Homework \342\204\2264/Phonebook/Phonebook/tests.h" @@ -0,0 +1,5 @@ +#pragma once +#include + +// Function for testing a function that finds a name by phone number +bool testFunctionsWorkingWithFile(); diff --git "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers.sln" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers.sln" new file mode 100644 index 0000000..b49f86d --- /dev/null +++ "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers.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}") = "additionOfNumbers", "additionOfNumbers\additionOfNumbers.vcxproj", "{A08BCEED-1B88-4D26-B359-79E74996FB01}" +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 + {A08BCEED-1B88-4D26-B359-79E74996FB01}.Debug|x64.ActiveCfg = Debug|x64 + {A08BCEED-1B88-4D26-B359-79E74996FB01}.Debug|x64.Build.0 = Debug|x64 + {A08BCEED-1B88-4D26-B359-79E74996FB01}.Debug|x86.ActiveCfg = Debug|Win32 + {A08BCEED-1B88-4D26-B359-79E74996FB01}.Debug|x86.Build.0 = Debug|Win32 + {A08BCEED-1B88-4D26-B359-79E74996FB01}.Release|x64.ActiveCfg = Release|x64 + {A08BCEED-1B88-4D26-B359-79E74996FB01}.Release|x64.Build.0 = Release|x64 + {A08BCEED-1B88-4D26-B359-79E74996FB01}.Release|x86.ActiveCfg = Release|Win32 + {A08BCEED-1B88-4D26-B359-79E74996FB01}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2E10007C-0307-4D02-8E34-DFE498F5CDC2} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj" new file mode 100644 index 0000000..9ecf018 --- /dev/null +++ "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj" @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {a08bceed-1b88-4d26-b359-79e74996fb01} + additionOfNumbers + 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/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj.filters" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.vcxproj.filters" new file mode 100644 index 0000000..9f5be3f --- /dev/null +++ "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/additionOfNumbers.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\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.c" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.c" new file mode 100644 index 0000000..d790566 --- /dev/null +++ "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.c" @@ -0,0 +1,49 @@ +#include "binaryNumberSystem.h" +#include + +void writeDigitsToArray(int* arrayOfNumber, int numberToWrite) +{ + for (int j = 0; j < sizeof(int) * 8; ++j) + { + arrayOfNumber[j] = ((numberToWrite & 1) ? 1 : 0); + numberToWrite >>= 1; + } +} + +void outputtingNumberInBinaryNotation(int* arrayOfNumber) +{ + for (int j = sizeof(int) * 8 - 1; j >= 0; --j) + { + printf("%d", arrayOfNumber[j]); + } +} + +void additionOfDigitsOfTwoNumbers(int* arrayOfDigitsOfTheFirstNumber, int* arrayOfDigitsOfTheSecondNumber,int* arrayForWritingTheSumOfDigits) +{ + int remainder = 0; + for (int j = 0; j < sizeof(int) * 8; ++j) + { + if (j > 0 && arrayOfDigitsOfTheFirstNumber[j - 1] + arrayOfDigitsOfTheSecondNumber[j - 1] + + remainder == 2 || j > 0 && arrayOfDigitsOfTheFirstNumber[j - 1] + arrayOfDigitsOfTheSecondNumber[j - 1] + remainder == 3) + { + remainder = 1; + } + else + { + remainder = 0; + } + arrayForWritingTheSumOfDigits[j] = (arrayOfDigitsOfTheFirstNumber[j] + arrayOfDigitsOfTheSecondNumber[j] + remainder) % 2; + } +} + +int convertNumberFromBinaryToDecimal(int* arrayForWritingTheSumOfDigits) +{ + int decimalNumber = 0; + int positionMagnifier = 1; + for (int j = 0; j <= sizeof(int) * 8 - 1; j++) + { + decimalNumber = decimalNumber | (arrayForWritingTheSumOfDigits[j] == 0 ? 0 : positionMagnifier); + positionMagnifier *= 2; + } + return decimalNumber; +} \ No newline at end of file diff --git "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.h" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.h" new file mode 100644 index 0000000..357a1e7 --- /dev/null +++ "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/binaryNumberSystem.h" @@ -0,0 +1,14 @@ +#pragma once + +//function for writing the digits of a number to an array. +//The digits are the binary representation of the number numberToWrite is written to the array arrayOfNumber +void writeDigitsToArray(int* arrayOfNumber, int numberToWrite); + +// function for outputting the digits of a number in binary form +void outputtingNumberInBinaryNotation(int* arrayOfNumber); + +// function for adding numbers in the binary number system +void additionOfDigitsOfTwoNumbers(int* arrayOfDigitsOfTheFirstNumber, int* arrayOfDigitsOfTheSecondNumber, int* arrayForWritingTheSumOfDigits); + +// function to convert a number from binary to decimal +int convertNumberFromBinaryToDecimal(int* arrayForWritingTheSumOfDigits); \ No newline at end of file diff --git "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/main.c" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/main.c" new file mode 100644 index 0000000..914646a --- /dev/null +++ "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/main.c" @@ -0,0 +1,48 @@ +#include +#include +#include "binaryNumberSystem.h" +#include "tests.h" + +int main() +{ + setlocale(LC_ALL, "rus"); + if (!testWritingDigitsToArray() || !testAdditionOfDigitsOfTwoNumbers() || !testConvertNumberFromBinaryToDecimal()) + { + printf("Tec "); + return -1; + } + int firstNumber = 0; + printf(" \n"); + const int scanfFirstNumberResult = scanf_s("%d", &firstNumber); + if (scanfFirstNumberResult == 0) + { + return -1; + } + int secondNumber = 0; + printf(" \n"); + const int scanfSecondNumberResult = scanf_s("%d", &secondNumber); + if (scanfSecondNumberResult == 0) + { + return -1; + } + + int arrayForWritingTheDigitsOfFirstNumber[8 * sizeof(int)] = { 0 }; + writeDigitsToArray(arrayForWritingTheDigitsOfFirstNumber, firstNumber); + printf(" 2 : "); + outputtingNumberInBinaryNotation(arrayForWritingTheDigitsOfFirstNumber); + printf("\n\n"); + + int arrayForWritingTheDigitsOfSecondNumber[8 * sizeof(int)] = { 0 }; + writeDigitsToArray(arrayForWritingTheDigitsOfSecondNumber, secondNumber); + printf(" 2 : "); + outputtingNumberInBinaryNotation(arrayForWritingTheDigitsOfSecondNumber); + printf("\n\n"); + + int arrayForWritingTheSumOfDigits[8 * sizeof(int)] = { 0 }; + additionOfDigitsOfTwoNumbers(arrayForWritingTheDigitsOfFirstNumber, arrayForWritingTheDigitsOfSecondNumber, arrayForWritingTheSumOfDigits); + printf(" 2 : "); + outputtingNumberInBinaryNotation(arrayForWritingTheSumOfDigits); + printf("\n\n"); + printf(" 10 : %d", convertNumberFromBinaryToDecimal(arrayForWritingTheSumOfDigits)); +} + diff --git "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.c" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.c" new file mode 100644 index 0000000..05f73e1 --- /dev/null +++ "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.c" @@ -0,0 +1,67 @@ +#include "tests.h" +#include "binaryNumberSystem.h" + +bool comparingDigitsInArrays(int* firstArrayOfDigits, int* secondArrayOFDigits) +{ + for(int j = 0; j < sizeof(int) * 8; j++) + { + if (firstArrayOfDigits[j] != secondArrayOFDigits[j]) + { + return false; + } + } + return true; +} + +bool testWritingDigitsToArray() +{ + // check for writing positive numbers + int representationOfNumber31[sizeof(int) * 8] = { 1, 1, 1, 1, 1 }; + int arrayForWritingTheNumber31[sizeof(int) * 8] = { 0 }; + writeDigitsToArray(arrayForWritingTheNumber31, 31); + int representationOfNumber123[sizeof(int) * 8] = { 1, 1, 0, 1, 1, 1, 1 }; + int arrayForWritingTheNumber123[sizeof(int) * 8] = { 0 }; + writeDigitsToArray(arrayForWritingTheNumber123, 123); + + // check for writing negative numbers + int representationOfNumberMinus12[sizeof(int) * 8] = { 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + int arrayForWritingTheNumberMinus12[sizeof(int) * 8] = { 0 }; + writeDigitsToArray(arrayForWritingTheNumberMinus12, -12); + int representationOfNumberMinus245[sizeof(int) * 8] = { 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + int arrayForWritingTheNumberMinus245[sizeof(int) * 8] = { 0 }; + writeDigitsToArray(arrayForWritingTheNumberMinus245, -245); + + return comparingDigitsInArrays(representationOfNumber31, arrayForWritingTheNumber31) + && comparingDigitsInArrays(representationOfNumber123, arrayForWritingTheNumber123) + && comparingDigitsInArrays(representationOfNumberMinus12, arrayForWritingTheNumberMinus12) + && comparingDigitsInArrays(representationOfNumberMinus245, arrayForWritingTheNumberMinus245); +} + +bool testAdditionOfDigitsOfTwoNumbers() +{ + int representationOfNumber31[sizeof(int) * 8] = { 1, 1, 1, 1, 1 }; + int representationOfNumberMinus12[sizeof(int) * 8] = { 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + int representationOfNumber19[sizeof(int) * 8] = { 1, 1, 0, 0, 1 }; + int arrayForWritingTheNumber19[sizeof(int) * 8] = { 0 }; + + int representationOfNumberMinus245[sizeof(int) * 8] = { 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + int representationOfNumber123[sizeof(int) * 8] = { 1, 1, 0, 1, 1, 1, 1 }; + int representationOfNumberMinus122[sizeof(int) * 8] = { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + int arrayForWritingTheNumberMinus122[sizeof(int) * 8] = { 0 }; + + additionOfDigitsOfTwoNumbers(representationOfNumber31, representationOfNumberMinus12, arrayForWritingTheNumber19); + additionOfDigitsOfTwoNumbers(representationOfNumberMinus245, representationOfNumber123, arrayForWritingTheNumberMinus122); + + return comparingDigitsInArrays(representationOfNumberMinus122, arrayForWritingTheNumberMinus122) + && comparingDigitsInArrays(representationOfNumber19, arrayForWritingTheNumber19); +} + +bool testConvertNumberFromBinaryToDecimal() +{ + int representationOfNumber31[sizeof(int) * 8] = { 1, 1, 1, 1, 1 }; + int representationOfNumberMinus12[sizeof(int) * 8] = { 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + int representationOfNumber19[sizeof(int) * 8] = { 1, 1, 0, 0, 1 }; + return convertNumberFromBinaryToDecimal(representationOfNumber19) == 19 + && convertNumberFromBinaryToDecimal(representationOfNumber31) == 31 + && convertNumberFromBinaryToDecimal(representationOfNumberMinus12) == -12; +} \ No newline at end of file diff --git "a/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.h" "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.h" new file mode 100644 index 0000000..568156e --- /dev/null +++ "b/Homework \342\204\2264/additionOfNumbers/additionOfNumbers/tests.h" @@ -0,0 +1,11 @@ +#pragma once +#include + +// function to check the correct translation of a number into a binary system +bool testWritingDigitsToArray(); + +// function for checking the correct addition of two numbers in a binary system +bool testAdditionOfDigitsOfTwoNumbers(); + +// function for checking the correct conversion of a number to the decimal system +bool testConvertNumberFromBinaryToDecimal(); diff --git a/Tree/Tree/Main.c b/Tree/Tree/Main.c deleted file mode 100644 index 48035ec..0000000 --- a/Tree/Tree/Main.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "Tree.h" -#include "TestTree.h" - -int main() -{ - if (!testAddNode() || !testDeleteNode() || !testInTree() || !testGetValue()) - { - return -1; - } -} \ No newline at end of file diff --git a/Tree/Tree/TestTree.c b/Tree/Tree/TestTree.c deleted file mode 100644 index 21b7feb..0000000 --- a/Tree/Tree/TestTree.c +++ /dev/null @@ -1,91 +0,0 @@ -#include "TestTree.h" -#include "Tree.h" -#include - -bool testAddNode() -{ - Error error = NOT_ERROR; - Node* tree = createTree(); - tree = addNode(tree, 3, "awa", &error); - tree = addNode(tree, 5, "sdadad", &error); - bool firstCheck = isFather(tree, 5, 3); - tree = addNode(tree, 1, "wdwddw", &error); - bool secondCheck = isFather(tree, 1, 3); - bool thirdCheck = isFather(tree, 3, 5); - tree = addNode(tree, 6, "afwfwfw", &error); - bool fourthCheck = isFather(tree, 6, 1); - bool fifthCheck = isFather(tree, 1, 5); - bool sixthCheck = isFather(tree, 5, 3); - tree = addNode(tree, 2, "adwdwd", &error); - bool seventhCheck = isFather(tree, 2, 1); - bool eighthCheck = isFather(tree, 2, 6); - bool ninthCheck = isFather(tree, 6, 3); - bool tenthCheck = isFather(tree, 3, 5); - deleteTree(&tree); - return firstCheck && secondCheck && thirdCheck - && fourthCheck && fifthCheck && sixthCheck - && seventhCheck && eighthCheck && ninthCheck && tenthCheck && error == NOT_ERROR; -} - -bool testDeleteNode() -{ - Error error = NOT_ERROR; - Node* tree = createTree(); - tree = addNode(tree, 3, "Hello World", &error); - tree = addNode(tree, 8, "Hello army", &error); - tree = addNode(tree, 1, "AVL tree", &error); - tree = addNode(tree, -8, "^-^", &error); - tree = addNode(tree, 12, "Test", &error); - tree = addNode(tree, 2, "git commit", &error); - tree = deleteNode(tree, 12, &error); - bool firstCheck = inTree(tree, 12); - tree = deleteNode(tree, 1, &error); - bool secondCheck = inTree(tree, 1); - tree = deleteNode(tree, -8, &error); - bool thirdCheck = inTree(tree, -8); - deleteTree(&tree); - return !firstCheck && !secondCheck && !thirdCheck && error == NOT_ERROR; -} - -bool testInTree() -{ - Error error = NOT_ERROR; - Node* tree = createTree(); - tree = addNode(tree, 3, "cyclic list", &error); - tree = addNode(tree, -123, "Memory link", &error); - tree = addNode(tree, 10, "git checkout -b", &error); - tree = addNode(tree, -5, "eeeeee", &error); - tree = addNode(tree, 12, "stormbringer", &error); - tree = addNode(tree, 2, "i surrender", &error); - bool firstCheck = inTree(tree, 3); - bool secondCheck = inTree(tree, -5); - bool thirdCheck = inTree(tree, 12); - bool fourthCheck = inTree(tree, 2); - bool fifthCheck = inTree(tree,-123); - - bool sixthCheck = inTree(tree, 2021); - tree = deleteNode(tree, 2, &error); - bool seventhCheck = inTree(tree, 2); - bool eighthCheck = inTree(tree, 0); - tree = deleteNode(tree, -123, &error); - bool ninthCheck = inTree(tree, -123); - bool tenthCheck = inTree(tree, -47); - deleteTree(&tree); - return firstCheck && secondCheck && thirdCheck - && fourthCheck && fifthCheck && !sixthCheck - && !seventhCheck && !eighthCheck && !ninthCheck && !tenthCheck && error == NOT_ERROR; -} - -bool testGetValue() -{ - Error error = NOT_ERROR; - Node* tree = createTree(); - tree = addNode(tree, 3, "cyclic list", &error); - tree = addNode(tree, 10, "git checkout -b", &error); - const char* firstValue = getValue(tree, 3); - const char* secondValue = getValue(tree, 4); - const char* thirdValue = getValue(tree, 10); - bool result = strcmp(firstValue, "cyclic list") == 0 && strcmp(thirdValue, "git checkout -b") == 0 && secondValue == NULL && error == NOT_ERROR; - deleteTree(&tree); - return result; -} diff --git a/Tree/Tree/TestTree.h b/Tree/Tree/TestTree.h deleted file mode 100644 index f89c36c..0000000 --- a/Tree/Tree/TestTree.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include - -// Function to check the function that adds a node -bool testAddNode(); - -// Function to check the function that deletes the node -bool testDeleteNode(); - -// Function for checking a function that checks for the presence of a key -bool testInTree(); - -// Function for checking a function that gets values by key -bool testGetValue(); \ No newline at end of file diff --git a/Tree/Tree/Tree.c b/Tree/Tree/Tree.c deleted file mode 100644 index 2071309..0000000 --- a/Tree/Tree/Tree.c +++ /dev/null @@ -1,377 +0,0 @@ -#include "Tree.h" -#include -#include - -typedef struct Node -{ - struct Node* leftSon; - struct Node* rightSon; - struct Node* parent; - int key; - char* value; -} 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); -} - -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; - } -} - -void zig(Node* x) -{ - Node* father = x->parent; - if (x == father->leftSon) - { - Node* rightSon = x->rightSon; - attach(x, father, right); - attach(father, rightSon, left); - } - else - { - Node* leftSon = x->leftSon; - attach(x, father, left); - attach(father, leftSon, right); - } - x->parent = NULL; -} - -void zigZig(Node* x) -{ - Node* father = x->parent; - Node* grandFather = father->parent; - Node* grandGrandFather = grandFather->parent; - if (x == father->leftSon) - { - Node* rightSon = x->rightSon; - Node* bro = father->rightSon; - attach(father, rightSon, left); - attach(grandFather, bro, left); - attach(father, grandFather, right); - attach(x, father, right); - } - else if (x == father->rightSon) - { - Node* leftSon = x->leftSon; - Node* bro = father->leftSon; - attach(father, leftSon, right); - attach(grandFather, bro, right); - attach(father, grandFather, left); - attach(x, father, left); - } - if (grandGrandFather != NULL) - { - if (grandGrandFather->leftSon == grandFather) - { - grandGrandFather->leftSon = x; - } - else if (grandGrandFather->rightSon == grandFather) - { - grandGrandFather->rightSon = x; - } - } - x->parent = grandGrandFather; -} - -void zigZag(Node* x) -{ - Node* father = x->parent; - Node* grandFather = father->parent; - Node* grandGrandFather = grandFather->parent; - if (father->rightSon == x) - { - Node* leftSon = x->leftSon; - Node* rightSon = x->rightSon; - attach(x, father, left); - attach(grandFather, rightSon, left); - attach(father, leftSon, right); - attach(x, grandFather, right); - } - else if (father->leftSon == x) - { - Node* leftSon = x->leftSon; - Node* rightSon = x->rightSon; - attach(x, father, right); - attach(grandFather, leftSon, right); - attach(father, rightSon, left); - attach(x, grandFather, left); - } - if (grandGrandFather != NULL) - { - if (grandGrandFather->leftSon == grandFather) - { - grandGrandFather->leftSon = x; - } - else if (grandGrandFather->rightSon == grandFather) - { - grandGrandFather->rightSon = x; - } - } - x->parent = grandGrandFather; -} - -Node* splay(Node* x) -{ - if (x->parent == NULL) - { - return x; - } - if (x->parent->parent == NULL) - { - zig(x); - return x; - } - if ((x->parent->leftSon == x && x->parent->parent->leftSon == x->parent) - || (x->parent->rightSon == x && x->parent->parent->rightSon == x->parent)) - { - zigZig(x); - } - else - { - zigZag(x); - } - return splay(x); -} - - -Node* addNode(Node* root, int key, const char* value, Error* error) -{ - if (*error != NOT_ERROR) - { - return root; - } - char* copyValue = calloc(strlen(value) + 1, sizeof(char)); - if (copyValue == NULL) - { - *error = INSUFFICIENT_MEMORY; - return root; - } - strcpy(copyValue, value); - Node* newRoot = (Node*)calloc(1, sizeof(Node)); - if (newRoot == NULL) - { - *error = INSUFFICIENT_MEMORY; - free(copyValue); - return root; - } - if (root == NULL) - { - newRoot->key = key; - newRoot->value = copyValue; - return newRoot; - } - Node* i = root; - while (i != NULL) - { - if (key > i->key) - { - if (i->rightSon == NULL) - { - newRoot->key = key; - newRoot->value = copyValue; - i->rightSon = newRoot; - newRoot->parent = i; - return splay(newRoot); - } - i = i->rightSon; - } - else if (key == i->key) - { - free(i->value); - i->value = copyValue; - i->key = key; - return splay(i); - } - else - { - if (i->leftSon == NULL) - { - newRoot->key = key; - newRoot->value = copyValue; - i->leftSon = newRoot; - newRoot->parent = i; - return splay(newRoot); - } - i = i->leftSon; - } - } - free(newRoot); - free(copyValue); - return root; -} - -void search(Node** root, int key) -{ - Node* i = *root; - while (i != NULL) - { - if (key > i->key) - { - i = i->rightSon; - } - else if (key < i->key) - { - i = i->leftSon; - } - else - { - *root = i; - return; - } - } - *root = NULL; -} - -bool inTree(Node* root, int key) -{ - search(&root, key); - return root != NULL; -} - -Node* deleteNode(Node* root, int key, Error* error) -{ - if (*error != NOT_ERROR) - { - return root; - } - search(&root, key); - if (root == NULL) - { - *error = ROOT_IS_MISSING; - return root; - } - if (root->rightSon == NULL && root->leftSon == NULL) - { - Node* parent = root->parent; - if (parent != NULL) - { - if (root->parent->rightSon == root) - { - root->parent->rightSon = NULL; - } - else - { - root->parent->leftSon = NULL; - } - } - free(root->value); - free(root); - return (parent == NULL) ? NULL : splay(parent); - } - 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; - parent == NULL ? attach(currentRoot, root->rightSon, right) - : attach(root->parent, root->leftSon, left); - if (parent == NULL) - { - currentRoot->parent = NULL; - } - free(root->value); - free(root); - return parent == NULL ? currentRoot : splay(currentRoot->parent); - } - Node* currentRootParent = currentRoot->parent; - root->key = currentRoot->key; - char* newValue = calloc(strlen(root->value) + 1, sizeof(char)); - if (newValue == NULL) - { - *error = INSUFFICIENT_MEMORY; - return root; - } - free(root->value); - strcpy(newValue, currentRoot->value); - root->value = newValue; - currentRootParent->rightSon = NULL; - free(currentRoot->value); - free(currentRoot); - return splay(currentRootParent); - } - if (root->parent == NULL) - { - root = root->rightSon == NULL ? root->leftSon : root->rightSon; - if (root->parent != NULL) - { - free(root->parent->value); - } - free(root->parent); - root->parent = NULL; - return root; - } - Node* parent = root->parent; - if (root->rightSon == NULL) - { - parent->leftSon == root ? attach(parent,root->leftSon,left) - : attach(parent,root->leftSon, right); - } - else - { - parent->leftSon == root ? attach(parent, root->rightSon, left) - : attach(parent, root->rightSon, right); - } - free(root->value); - free(root); - return splay(parent); -} - -bool isFather(Node* tree, int parentKey, int childKey) -{ - search(&tree, childKey); - return tree->parent->key == parentKey && tree->key == childKey; -} - -char* getValue(Node* root, int key) -{ - search(&root, key); - if (root == NULL) - { - return NULL; - } - return root->value; -} \ No newline at end of file diff --git a/Tree/Tree/Tree.h b/Tree/Tree/Tree.h deleted file mode 100644 index 2ccd2d9..0000000 --- a/Tree/Tree/Tree.h +++ /dev/null @@ -1,33 +0,0 @@ -#include - -// Structure representing a tree -typedef struct Node Node; - -// Structure representing a tree -typedef enum Error -{ - NOT_ERROR, - ROOT_IS_MISSING, - INSUFFICIENT_MEMORY -} Error; - -// Function for creating a tree -Node* createTree(); - -// Function for deleting a tree -void deleteTree(Node** root); - -// Function for adding a node -Node* addNode(Node* root, int key, const char* value, Error* error); - -// Function for checking the availability of a key -bool inTree(Node* root, int key); - -// Function for deleting a node -Node* deleteNode(Node* root, int key, Error* error); - -// Function for checking the node for paternity -bool isFather(Node* tree, int parentKey, int childKey); - -// Function of getting a value by key -char* getValue(Node* root, int key); \ No newline at end of file From 9a5fcff60feae307a42c6338fcbef53f0cdd29a8 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 26 Nov 2021 14:06:07 +0300 Subject: [PATCH 6/6] the necessary files have been restored --- "Homework \342\204\2267/Number1/Number1.sln" | 31 ++ .../Number1/Number1/Main.c" | 125 ++++++ .../Number1/Number1/Number1.vcxproj" | 152 +++++++ .../Number1/Number1/Number1.vcxproj.filters" | 33 ++ "Homework \342\204\2267/Tree/Tree.sln" | 31 ++ "Homework \342\204\2267/Tree/Tree/Main.c" | 10 + "Homework \342\204\2267/Tree/Tree/TestTree.c" | 91 ++++ "Homework \342\204\2267/Tree/Tree/TestTree.h" | 14 + "Homework \342\204\2267/Tree/Tree/Tree.c" | 394 ++++++++++++++++++ "Homework \342\204\2267/Tree/Tree/Tree.h" | 33 ++ .../Tree/Tree/Tree.vcxproj" | 153 +++++++ .../Tree/Tree/Tree.vcxproj.filters" | 36 ++ 12 files changed, 1103 insertions(+) create mode 100644 "Homework \342\204\2267/Number1/Number1.sln" create mode 100644 "Homework \342\204\2267/Number1/Number1/Main.c" create mode 100644 "Homework \342\204\2267/Number1/Number1/Number1.vcxproj" create mode 100644 "Homework \342\204\2267/Number1/Number1/Number1.vcxproj.filters" create mode 100644 "Homework \342\204\2267/Tree/Tree.sln" create mode 100644 "Homework \342\204\2267/Tree/Tree/Main.c" create mode 100644 "Homework \342\204\2267/Tree/Tree/TestTree.c" create mode 100644 "Homework \342\204\2267/Tree/Tree/TestTree.h" create mode 100644 "Homework \342\204\2267/Tree/Tree/Tree.c" create mode 100644 "Homework \342\204\2267/Tree/Tree/Tree.h" create mode 100644 "Homework \342\204\2267/Tree/Tree/Tree.vcxproj" create mode 100644 "Homework \342\204\2267/Tree/Tree/Tree.vcxproj.filters" diff --git "a/Homework \342\204\2267/Number1/Number1.sln" "b/Homework \342\204\2267/Number1/Number1.sln" new file mode 100644 index 0000000..c37b494 --- /dev/null +++ "b/Homework \342\204\2267/Number1/Number1.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}") = "Number1", "Number1\Number1.vcxproj", "{3F278950-A66B-4F9F-91D5-768E2910EB77}" +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 + {3F278950-A66B-4F9F-91D5-768E2910EB77}.Debug|x64.ActiveCfg = Debug|x64 + {3F278950-A66B-4F9F-91D5-768E2910EB77}.Debug|x64.Build.0 = Debug|x64 + {3F278950-A66B-4F9F-91D5-768E2910EB77}.Debug|x86.ActiveCfg = Debug|Win32 + {3F278950-A66B-4F9F-91D5-768E2910EB77}.Debug|x86.Build.0 = Debug|Win32 + {3F278950-A66B-4F9F-91D5-768E2910EB77}.Release|x64.ActiveCfg = Release|x64 + {3F278950-A66B-4F9F-91D5-768E2910EB77}.Release|x64.Build.0 = Release|x64 + {3F278950-A66B-4F9F-91D5-768E2910EB77}.Release|x86.ActiveCfg = Release|Win32 + {3F278950-A66B-4F9F-91D5-768E2910EB77}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7C0DA989-2AA5-485B-9AF3-4A74C3CC0A9B} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2267/Number1/Number1/Main.c" "b/Homework \342\204\2267/Number1/Number1/Main.c" new file mode 100644 index 0000000..e12548f --- /dev/null +++ "b/Homework \342\204\2267/Number1/Number1/Main.c" @@ -0,0 +1,125 @@ +#include "../../Tree/Tree/Tree.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; + Error 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(", \n"); + int key = 0; + const int firstScanfResult = scanf_s("%d", &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 == INSUFFICIENT_MEMORY) + { + deleteTree(&tree); + printf(" \n"); + return -1; + } + printf(" \n"); + break; + } + case 2: + { + printf(", \n"); + int key = 0; + const int firstScanfResult = scanf_s("%d", &key); + if (firstScanfResult == 0) + { + printf(" \n"); + break; + } + printf("%s\n", getValue(tree, key)); + break; + } + case 3: + { + printf(", \n"); + int key = 0; + const int firstScanfResult = scanf_s("%d", &key); + if (firstScanfResult == 0) + { + printf(" \n"); + break; + } + bool result = inTree(tree, key); + if (!result) + { + printf(" \n"); + break; + } + printf(" \n"); + break; + } + case 4: + { + printf(", \n"); + int key = 0; + const int firstScanfResult = scanf_s("%d", &key); + if (firstScanfResult == 0) + { + printf(" \n"); + break; + } + deleteNode(&tree, key, &error); + if (error == INSUFFICIENT_MEMORY) + { + printf(" \n"); + return -1; + } + if (error == ROOT_IS_MISSING) + { + printf(" \n"); + break; + } + printf(" \n"); + break; + } + default: + { + printf(", , 0 4\n"); + break; + } + } + } +} \ No newline at end of file diff --git "a/Homework \342\204\2267/Number1/Number1/Number1.vcxproj" "b/Homework \342\204\2267/Number1/Number1/Number1.vcxproj" new file mode 100644 index 0000000..9e84ce5 --- /dev/null +++ "b/Homework \342\204\2267/Number1/Number1/Number1.vcxproj" @@ -0,0 +1,152 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {3f278950-a66b-4f9f-91d5-768e2910eb77} + Number1 + 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;_CRT_SECURE_NO_WARNINGS;%(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\2267/Number1/Number1/Number1.vcxproj.filters" "b/Homework \342\204\2267/Number1/Number1/Number1.vcxproj.filters" new file mode 100644 index 0000000..a1c2d4c --- /dev/null +++ "b/Homework \342\204\2267/Number1/Number1/Number1.vcxproj.filters" @@ -0,0 +1,33 @@ + + + + + {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\2267/Tree/Tree.sln" "b/Homework \342\204\2267/Tree/Tree.sln" new file mode 100644 index 0000000..a09c740 --- /dev/null +++ "b/Homework \342\204\2267/Tree/Tree.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}") = "Tree", "Tree\Tree.vcxproj", "{1B08B554-064D-4A2D-A418-3C73FF3D4652}" +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 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Debug|x64.ActiveCfg = Debug|x64 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Debug|x64.Build.0 = Debug|x64 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Debug|x86.ActiveCfg = Debug|Win32 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Debug|x86.Build.0 = Debug|Win32 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Release|x64.ActiveCfg = Release|x64 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Release|x64.Build.0 = Release|x64 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Release|x86.ActiveCfg = Release|Win32 + {1B08B554-064D-4A2D-A418-3C73FF3D4652}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0EEF711C-36E8-4AC3-9FFA-66083037F612} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\2267/Tree/Tree/Main.c" "b/Homework \342\204\2267/Tree/Tree/Main.c" new file mode 100644 index 0000000..48035ec --- /dev/null +++ "b/Homework \342\204\2267/Tree/Tree/Main.c" @@ -0,0 +1,10 @@ +#include "Tree.h" +#include "TestTree.h" + +int main() +{ + if (!testAddNode() || !testDeleteNode() || !testInTree() || !testGetValue()) + { + return -1; + } +} \ No newline at end of file diff --git "a/Homework \342\204\2267/Tree/Tree/TestTree.c" "b/Homework \342\204\2267/Tree/Tree/TestTree.c" new file mode 100644 index 0000000..b716487 --- /dev/null +++ "b/Homework \342\204\2267/Tree/Tree/TestTree.c" @@ -0,0 +1,91 @@ +#include "TestTree.h" +#include "Tree.h" +#include + +bool testAddNode() +{ + Error error = NOT_ERROR; + Node* tree = createTree(); + tree = addNode(tree, 3, "awa", &error); + tree = addNode(tree, 5, "sdadad", &error); + bool firstCheck = invariant(tree, 5, 3); + tree = addNode(tree, 1, "wdwddw", &error); + bool secondCheck = invariant(tree, 1, 3); + bool thirdCheck = invariant(tree, 3, 5); + tree = addNode(tree, 6, "afwfwfw", &error); + bool fourthCheck = invariant(tree, 6, 1); + bool fifthCheck = invariant(tree, 1, 5); + bool sixthCheck = invariant(tree, 5, 3); + tree = addNode(tree, 2, "adwdwd", &error); + bool seventhCheck = invariant(tree, 2, 1); + bool eighthCheck = invariant(tree, 2, 6); + bool ninthCheck = invariant(tree, 6, 3); + bool tenthCheck = invariant(tree, 3, 5); + deleteTree(&tree); + return firstCheck && secondCheck && thirdCheck + && fourthCheck && fifthCheck && sixthCheck + && seventhCheck && eighthCheck && ninthCheck && tenthCheck && error == NOT_ERROR; +} + +bool testDeleteNode() +{ + Error error = NOT_ERROR; + Node* tree = createTree(); + tree = addNode(tree, 3, "Hello World", &error); + tree = addNode(tree, 8, "Hello army", &error); + tree = addNode(tree, 1, "AVL tree", &error); + tree = addNode(tree, -8, "^-^", &error); + tree = addNode(tree, 12, "Test", &error); + tree = addNode(tree, 2, "git commit", &error); + deleteNode(&tree, 12, &error); + bool firstCheck = inTree(tree, 12); + deleteNode(&tree, 1, &error); + bool secondCheck = inTree(tree, 1); + deleteNode(&tree, -8, &error); + bool thirdCheck = inTree(tree, -8); + deleteTree(&tree); + return !firstCheck && !secondCheck && !thirdCheck && error == NOT_ERROR; +} + +bool testInTree() +{ + Error error = NOT_ERROR; + Node* tree = createTree(); + tree = addNode(tree, 3, "cyclic list", &error); + tree = addNode(tree, -123, "Memory link", &error); + tree = addNode(tree, 10, "git checkout -b", &error); + tree = addNode(tree, -5, "eeeeee", &error); + tree = addNode(tree, 12, "stormbringer", &error); + tree = addNode(tree, 2, "i surrender", &error); + bool firstCheck = inTree(tree, 3); + bool secondCheck = inTree(tree, -5); + bool thirdCheck = inTree(tree, 12); + bool fourthCheck = inTree(tree, 2); + bool fifthCheck = inTree(tree,-123); + + bool sixthCheck = inTree(tree, 2021); + deleteNode(&tree, 2, &error); + bool seventhCheck = inTree(tree, 2); + bool eighthCheck = inTree(tree, 0); + deleteNode(&tree, -123, &error); + bool ninthCheck = inTree(tree, -123); + bool tenthCheck = inTree(tree, -47); + deleteTree(&tree); + return firstCheck && secondCheck && thirdCheck + && fourthCheck && fifthCheck && !sixthCheck + && !seventhCheck && !eighthCheck && !ninthCheck && !tenthCheck && error == NOT_ERROR; +} + +bool testGetValue() +{ + Error error = NOT_ERROR; + Node* tree = createTree(); + tree = addNode(tree, 3, "cyclic list", &error); + tree = addNode(tree, 10, "git checkout -b", &error); + const char* firstValue = getValue(tree, 3); + const char* secondValue = getValue(tree, 4); + const char* thirdValue = getValue(tree, 10); + bool result = strcmp(firstValue, "cyclic list") == 0 && strcmp(thirdValue, "git checkout -b") == 0 && secondValue == NULL && error == NOT_ERROR; + deleteTree(&tree); + return result; +} diff --git "a/Homework \342\204\2267/Tree/Tree/TestTree.h" "b/Homework \342\204\2267/Tree/Tree/TestTree.h" new file mode 100644 index 0000000..f89c36c --- /dev/null +++ "b/Homework \342\204\2267/Tree/Tree/TestTree.h" @@ -0,0 +1,14 @@ +#pragma once +#include + +// Function to check the function that adds a node +bool testAddNode(); + +// Function to check the function that deletes the node +bool testDeleteNode(); + +// Function for checking a function that checks for the presence of a key +bool testInTree(); + +// Function for checking a function that gets values by key +bool testGetValue(); \ No newline at end of file diff --git "a/Homework \342\204\2267/Tree/Tree/Tree.c" "b/Homework \342\204\2267/Tree/Tree/Tree.c" new file mode 100644 index 0000000..8c1dc5b --- /dev/null +++ "b/Homework \342\204\2267/Tree/Tree/Tree.c" @@ -0,0 +1,394 @@ +#include "Tree.h" +#include +#include + +typedef struct Node +{ + struct Node* leftSon; + struct Node* rightSon; + struct Node* parent; + int key; + char* value; +} 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); +} + +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; + } +} + +void zig(Node* x) +{ + Node* father = x->parent; + if (x == father->leftSon) + { + Node* rightSon = x->rightSon; + attach(x, father, right); + attach(father, rightSon, left); + } + else + { + Node* leftSon = x->leftSon; + attach(x, father, left); + attach(father, leftSon, right); + } + x->parent = NULL; +} + +void zigZig(Node* x) +{ + Node* father = x->parent; + Node* grandFather = father->parent; + Node* grandGrandFather = grandFather->parent; + if (x == father->leftSon) + { + Node* rightSon = x->rightSon; + Node* bro = father->rightSon; + attach(father, rightSon, left); + attach(grandFather, bro, left); + attach(father, grandFather, right); + attach(x, father, right); + } + else if (x == father->rightSon) + { + Node* leftSon = x->leftSon; + Node* bro = father->leftSon; + attach(father, leftSon, right); + attach(grandFather, bro, right); + attach(father, grandFather, left); + attach(x, father, left); + } + if (grandGrandFather != NULL) + { + if (grandGrandFather->leftSon == grandFather) + { + grandGrandFather->leftSon = x; + } + else if (grandGrandFather->rightSon == grandFather) + { + grandGrandFather->rightSon = x; + } + } + x->parent = grandGrandFather; +} + +void zigZag(Node* x) +{ + Node* father = x->parent; + Node* grandFather = father->parent; + Node* grandGrandFather = grandFather->parent; + if (father->rightSon == x) + { + Node* leftSon = x->leftSon; + Node* rightSon = x->rightSon; + attach(x, father, left); + attach(grandFather, rightSon, left); + attach(father, leftSon, right); + attach(x, grandFather, right); + } + else if (father->leftSon == x) + { + Node* leftSon = x->leftSon; + Node* rightSon = x->rightSon; + attach(x, father, right); + attach(grandFather, leftSon, right); + attach(father, rightSon, left); + attach(x, grandFather, left); + } + if (grandGrandFather != NULL) + { + if (grandGrandFather->leftSon == grandFather) + { + grandGrandFather->leftSon = x; + } + else if (grandGrandFather->rightSon == grandFather) + { + grandGrandFather->rightSon = x; + } + } + x->parent = grandGrandFather; +} + +Node* splay(Node* x) +{ + if (x->parent == NULL) + { + return x; + } + if (x->parent->parent == NULL) + { + zig(x); + return x; + } + if ((x->parent->leftSon == x && x->parent->parent->leftSon == x->parent) + || (x->parent->rightSon == x && x->parent->parent->rightSon == x->parent)) + { + zigZig(x); + } + else + { + zigZag(x); + } + return splay(x); +} + + +Node* addNode(Node* root, int key, const char* value, Error* error) +{ + if (*error != NOT_ERROR) + { + return root; + } + char* copyValue = calloc(strlen(value) + 1, sizeof(char)); + if (copyValue == NULL) + { + *error = INSUFFICIENT_MEMORY; + return root; + } + strcpy(copyValue, value); + if (root == NULL) + { + Node* newRoot = (Node*)calloc(1, sizeof(Node)); + if (newRoot == NULL) + { + *error = INSUFFICIENT_MEMORY; + free(copyValue); + return root; + } + newRoot->key = key; + newRoot->value = copyValue; + return newRoot; + } + Node* currentRoot = root; + while (currentRoot != NULL) + { + if (key > currentRoot->key) + { + if (currentRoot->rightSon == NULL) + { + Node* newRoot = (Node*)calloc(1, sizeof(Node)); + if (newRoot == NULL) + { + *error = INSUFFICIENT_MEMORY; + free(copyValue); + return root; + } + newRoot->key = key; + newRoot->value = copyValue; + attach(currentRoot, newRoot, right); + return splay(newRoot); + } + currentRoot = currentRoot->rightSon; + } + else if (key == currentRoot->key) + { + free(currentRoot->value); + currentRoot->value = copyValue; + return splay(currentRoot); + } + else + { + if (currentRoot->leftSon == NULL) + { + Node* newRoot = (Node*)calloc(1, sizeof(Node)); + if (newRoot == NULL) + { + *error = INSUFFICIENT_MEMORY; + free(copyValue); + return root; + } + newRoot->key = key; + newRoot->value = copyValue; + attach(currentRoot, newRoot, left); + return splay(newRoot); + } + currentRoot = currentRoot->leftSon; + } + } + free(copyValue); + return root; +} + +Node* search(Node* root, int key) +{ + Node* newRoot = root; + while (newRoot != NULL) + { + if (key > newRoot->key) + { + newRoot = newRoot->rightSon; + } + else if (key < newRoot->key) + { + newRoot = newRoot->leftSon; + } + else + { + return newRoot; + } + } + return NULL; +} + +bool inTree(Node* root, int key) +{ + Node* searchResult = search(root, key); + return searchResult != NULL; +} + +void deleteNode(Node** root, int key, Error* error) +{ + if (*error != NOT_ERROR) + { + return; + } + Node* searchResult = search(*root, key); + if (searchResult == NULL) + { + *error = ROOT_IS_MISSING; + 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; + } + else + { + (*root)->parent->leftSon = NULL; + } + } + free((*root)->value); + free(*root); + (*root) = (parent != NULL) ? splay(parent) : NULL; + 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 + { + attach((*root)->parent, (*root)->leftSon, left); + } + free((*root)->value); + free(*root); + *root = parent == NULL ? currentRoot : splay(currentRoot->parent); + return; + } + Node* currentRootParent = currentRoot->parent; + (*root)->key = currentRoot->key; + char* newValue = calloc(strlen(currentRoot->value) + 1, sizeof(char)); + if (newValue == NULL) + { + *error = INSUFFICIENT_MEMORY; + return; + } + free((*root)->value); + strcpy(newValue, currentRoot->value); + (*root)->value = newValue; + currentRootParent->rightSon = NULL; + free(currentRoot->value); + free(currentRoot); + *root = splay(currentRootParent); + return; + } + if ((*root)->parent == NULL) + { + *root = (*root)->rightSon == NULL ? (*root)->leftSon : (*root)->rightSon; + if ((*root)->parent != NULL) + { + free((*root)->parent->value); + } + free((*root)->parent); + (*root)->parent = NULL; + return; + } + Node* parent = (*root)->parent; + if ((*root)->rightSon == NULL) + { + parent->leftSon == *root ? attach(parent, (*root)->leftSon, left) + : attach(parent, (*root)->leftSon, right); + } + else + { + parent->leftSon == *root ? attach(parent, (*root)->rightSon, left) + : attach(parent, (*root)->rightSon, right); + } + free((*root)->value); + free(*root); + *root = splay(parent); + return; +} + +bool invariant(Node* tree, int parentKey, int childKey) +{ + Node* searchResult = search(tree, childKey); + return searchResult->parent->key == parentKey && searchResult->key == childKey; +} + +char* getValue(Node* root, int key) +{ + Node* searchResult = search(root, key); + if (searchResult == NULL) + { + return NULL; + } + return searchResult->value; +} \ No newline at end of file diff --git "a/Homework \342\204\2267/Tree/Tree/Tree.h" "b/Homework \342\204\2267/Tree/Tree/Tree.h" new file mode 100644 index 0000000..5bafa26 --- /dev/null +++ "b/Homework \342\204\2267/Tree/Tree/Tree.h" @@ -0,0 +1,33 @@ +#include + +// Structure representing a tree +typedef struct Node Node; + +// Structure representing a tree +typedef enum Error +{ + NOT_ERROR, + ROOT_IS_MISSING, + INSUFFICIENT_MEMORY +} Error; + +// Function for creating a tree +Node* createTree(); + +// Function for deleting a tree +void deleteTree(Node** root); + +// Function for adding a node +Node* addNode(Node* root, int key, const char* value, Error* error); + +// Function for checking the availability of a key +bool inTree(Node* root, int key); + +// Function for deleting a node +void deleteNode(Node** root, int key, Error* error); + +// Function for checking the tree invariant +bool invariant(Node* tree, int firstKey, int secondKey); + +// Function of getting a value by key +char* getValue(Node* root, int key); \ No newline at end of file diff --git "a/Homework \342\204\2267/Tree/Tree/Tree.vcxproj" "b/Homework \342\204\2267/Tree/Tree/Tree.vcxproj" new file mode 100644 index 0000000..1f66300 --- /dev/null +++ "b/Homework \342\204\2267/Tree/Tree/Tree.vcxproj" @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {1b08b554-064d-4a2d-a418-3c73ff3d4652} + Tree + 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;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(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\2267/Tree/Tree/Tree.vcxproj.filters" "b/Homework \342\204\2267/Tree/Tree/Tree.vcxproj.filters" new file mode 100644 index 0000000..b5b3253 --- /dev/null +++ "b/Homework \342\204\2267/Tree/Tree/Tree.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