diff --git a/HomeworksAccept/homework21.09/read.me b/HomeworksAccept/homework21.09/read.me deleted file mode 100644 index 5e4d090..0000000 --- a/HomeworksAccept/homework21.09/read.me +++ /dev/null @@ -1 +0,0 @@ -3 домашка diff --git a/HomeworksAccept/homework28.09/read.me b/HomeworksAccept/homework28.09/read.me deleted file mode 100644 index 5061ad0..0000000 --- a/HomeworksAccept/homework28.09/read.me +++ /dev/null @@ -1 +0,0 @@ -4 домашка diff --git a/HomeworksAccept/read.me b/HomeworksAccept/read.me deleted file mode 100644 index 1773bf8..0000000 --- a/HomeworksAccept/read.me +++ /dev/null @@ -1 +0,0 @@ -Здесь представлены домашнии работы, прошедшии проверку diff --git a/sortedList/sortedList.sln b/sortedList/sortedList.sln new file mode 100644 index 0000000..c8c0db4 --- /dev/null +++ b/sortedList/sortedList.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sortedList", "sortedList\sortedList.vcxproj", "{C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}" +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 + {C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Debug|x64.ActiveCfg = Debug|x64 + {C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Debug|x64.Build.0 = Debug|x64 + {C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Debug|x86.ActiveCfg = Debug|Win32 + {C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Debug|x86.Build.0 = Debug|Win32 + {C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Release|x64.ActiveCfg = Release|x64 + {C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Release|x64.Build.0 = Release|x64 + {C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Release|x86.ActiveCfg = Release|Win32 + {C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2314527A-D566-40BA-9919-A77EF21F134B} + EndGlobalSection +EndGlobal diff --git a/sortedList/sortedList/list.c b/sortedList/sortedList/list.c new file mode 100644 index 0000000..72e7ed5 --- /dev/null +++ b/sortedList/sortedList/list.c @@ -0,0 +1,121 @@ +#include "list.h" +#include +#include + +typedef struct Node { + int value; + struct Node* next; +} Node; + +struct List { + Node* head; +}; + +void print(List* list) { + Node* walker = list->head; + while (walker != NULL) { + printf("%d ", walker->value); + walker = walker->next; + } + printf("\n"); +} + +bool isEmpty(List* list) { + return list->head == NULL; +} + +int insert(List* list, int value) { + Node* newNode = calloc(1, sizeof(Node)); + if (newNode == NULL) { + return -1; + } + newNode->value = value; + Node* currentNode = list->head; + + if (currentNode != NULL && currentNode->value >= value) { + newNode->next = currentNode; + list->head = newNode; + return 0; + } + + while (currentNode != NULL) { + if (currentNode->next == NULL || currentNode->next->value >= value) { + break; + } + currentNode = currentNode->next; + } + + if (currentNode == NULL) { + list->head = newNode; + return 0; + } + newNode->next = currentNode->next; + currentNode->next = newNode; + return 0; +} + +void clearList(List** list) { + if ((*list)->head != NULL) { + while ((*list)->head->next != NULL) { + Node* walker = (*list)->head; + while (walker->next != NULL && walker->next->next != NULL) { + walker = walker->next; + } + free(walker->next); + walker->next = NULL; + } + free((*list)->head->next); + free((*list)->head); + } + *list = NULL; +} + +int top(List* list) { + if (list->head == NULL) { + return -1; + } + return list->head->value; +} + +int delete(List* list, int value) { + Node* currentNode = list->head; + + if (isEmpty(list)) { + return -1; + } + if (currentNode->value == value) { + Node* temp = currentNode->next; + free(currentNode); + list->head = temp; + return 0; + } + + while (currentNode != NULL) { + if (currentNode->next == NULL || currentNode->next->value == value) { + if (currentNode->next == NULL && currentNode->value != value) { + return -1; + } + break; + } + currentNode = currentNode->next; + } + + if (currentNode == NULL) { + return -1; + } + + if (currentNode->next != NULL) { + Node* temp = currentNode->next->next; + free(currentNode->next); + currentNode->next = temp; + return 0; + } + + free(currentNode->next); + return 0; +} + +List* createList(void) { + List* list = calloc(1, sizeof(List)); + return list; +} \ No newline at end of file diff --git a/sortedList/sortedList/list.h b/sortedList/sortedList/list.h new file mode 100644 index 0000000..5eb6292 --- /dev/null +++ b/sortedList/sortedList/list.h @@ -0,0 +1,19 @@ +#pragma once +#include +#include + +typedef struct List List; + +int insert(List* list, int value); + +void print(List* list); + +int delete(List* list, int value); + +bool isEmpty(List* list); + +void clearList(List** list); + +List* createList(void); + +int top(List* list); \ No newline at end of file diff --git a/sortedList/sortedList/main.c b/sortedList/sortedList/main.c new file mode 100644 index 0000000..8123127 --- /dev/null +++ b/sortedList/sortedList/main.c @@ -0,0 +1,79 @@ +#include +#include +#include "list.h" +#include +#include + +int scanOne() { + int number = 0; + int checkScanf = scanf("%d", &number); + + while (checkScanf != 1) { + while (getchar() != '\n') { + } + + printf("%s", "... \n"); + checkScanf = scanf("%d", &number); + } + + return number; +} + +bool talkWithUser(void) { + List* list = createList(); + printf(" 0 \n 1 \n 2 \n 3 \n"); + int userComand = scanOne(); + while (userComand != 0) { + if (userComand == 1) { + printf(" \n"); + int value = scanOne(); + if (insert(list, value) == -1) { + return false; + } + } + else if (userComand == 2) { + printf(" \n"); + int number = scanOne(); + if (delete(list, number) == -1) { + printf(", !\n"); + } + } else if (userComand == 3) { + print(list); + } + printf(" \n"); + userComand = scanOne(); + } + + clearList(&list); + return true; +} + +bool tests() { + List* list = createList(); + insert(list, 100); + if (top(list) != 100) { + clearList(&list); + return false; + } + delete(list, 100); + if (top(list) != -1) { + clearList(&list); + return false; + } + clearList(&list); + return true; +} + +int main() { + setlocale(LC_ALL, "RUS"); + if (tests()) { + printf(" \n"); + } else { + printf("- ...\n"); + return 0; + } + bool check = talkWithUser(); + if (!check) { + printf(" ...\n"); + } +} \ No newline at end of file diff --git a/sortedList/sortedList/sortedList.vcxproj b/sortedList/sortedList/sortedList.vcxproj new file mode 100644 index 0000000..b776b0f --- /dev/null +++ b/sortedList/sortedList/sortedList.vcxproj @@ -0,0 +1,151 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {c52ffb7d-40d3-4bb3-92b4-a6f3e0b708f9} + sortedList + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + 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 + false + _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/sortedList/sortedList/sortedList.vcxproj.filters b/sortedList/sortedList/sortedList.vcxproj.filters new file mode 100644 index 0000000..b23289e --- /dev/null +++ b/sortedList/sortedList/sortedList.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + Исходные файлы + + + + + Исходные файлы + + + \ No newline at end of file