From f3b2155d4842ff7d30b3816d03026a3733530055 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 26 Nov 2021 13:09:43 +0300 Subject: [PATCH 01/16] put a space --- SinglyLinkedList/NewList/NewList/List.c | 1 - SinglyLinkedList/NewList/NewList/List.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/SinglyLinkedList/NewList/NewList/List.c b/SinglyLinkedList/NewList/NewList/List.c index 5972ee5..e690707 100644 --- a/SinglyLinkedList/NewList/NewList/List.c +++ b/SinglyLinkedList/NewList/NewList/List.c @@ -219,7 +219,6 @@ bool isOneElement(List* list) void print(List* list) { - int error = 0; ListElement* element = list->head; while (element != NULL) { diff --git a/SinglyLinkedList/NewList/NewList/List.h b/SinglyLinkedList/NewList/NewList/List.h index 808f752..18a8b17 100644 --- a/SinglyLinkedList/NewList/NewList/List.h +++ b/SinglyLinkedList/NewList/NewList/List.h @@ -13,7 +13,7 @@ typedef enum Error NOT_ERROR, EMPTY_LIST, INSUFFICIENT_MEMORY -}Error; +} Error; // Function for creating a list List* createList(); From e7ffca81f007f6ab352943690a3315953e34a4b5 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 20:37:41 +0300 Subject: [PATCH 02/16] changed error handling for some list function --- .../SinglyLinkedListForHashTable.sln | 31 +++ .../SinglyLinkedListForHashTable/Main.c | 9 + .../SinglyLinkedListForHashTable.c | 256 ++++++++++++++++++ .../SinglyLinkedListForHashTable.h | 59 ++++ .../SinglyLinkedListForHashTable.vcxproj | 153 +++++++++++ ...nglyLinkedListForHashTable.vcxproj.filters | 36 +++ .../TestSinglyLinkedListForHashTable.c | 98 +++++++ .../TestSinglyLinkedListForHashTable.h | 5 + 8 files changed, 647 insertions(+) create mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.sln create mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/Main.c create mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c create mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h create mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj create mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj.filters create mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c create mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.sln b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.sln new file mode 100644 index 0000000..d81aa68 --- /dev/null +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.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}") = "SinglyLinkedListForHashTable", "SinglyLinkedListForHashTable\SinglyLinkedListForHashTable.vcxproj", "{ABF8D20F-CBDB-4353-9BCC-D9ECC7866F3E}" +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 + {ABF8D20F-CBDB-4353-9BCC-D9ECC7866F3E}.Debug|x64.ActiveCfg = Debug|x64 + {ABF8D20F-CBDB-4353-9BCC-D9ECC7866F3E}.Debug|x64.Build.0 = Debug|x64 + {ABF8D20F-CBDB-4353-9BCC-D9ECC7866F3E}.Debug|x86.ActiveCfg = Debug|Win32 + {ABF8D20F-CBDB-4353-9BCC-D9ECC7866F3E}.Debug|x86.Build.0 = Debug|Win32 + {ABF8D20F-CBDB-4353-9BCC-D9ECC7866F3E}.Release|x64.ActiveCfg = Release|x64 + {ABF8D20F-CBDB-4353-9BCC-D9ECC7866F3E}.Release|x64.Build.0 = Release|x64 + {ABF8D20F-CBDB-4353-9BCC-D9ECC7866F3E}.Release|x86.ActiveCfg = Release|Win32 + {ABF8D20F-CBDB-4353-9BCC-D9ECC7866F3E}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {91BE3025-E290-44D1-8BF0-D958E20D7DD7} + EndGlobalSection +EndGlobal diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/Main.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/Main.c new file mode 100644 index 0000000..3be54fc --- /dev/null +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/Main.c @@ -0,0 +1,9 @@ +#include "TestSinglyLinkedListForHashTable.h" + +int main() +{ + if (!allTest()) + { + return -1; + } +} \ No newline at end of file diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c new file mode 100644 index 0000000..fd6d1cf --- /dev/null +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c @@ -0,0 +1,256 @@ +#include "SinglyLinkedListForHashTable.h" +#include +#include +#include +#include + +// Structure containing pointers to the beginning and end of the list +typedef struct List +{ + int size; + struct ListElement* head; + struct ListElement* tail; +} List; + +// Structure containing a pointer to the next list item and a value variable for the list items +typedef struct ListElement +{ + int numberOfDuplicateValues; + char* value; + struct ListElement* next; +} ListElement; + +// Structure containing a pointer to a ListElement +typedef struct Position +{ + ListElement* position; +} Position; + +List* createList(Error* error) +{ + List* list = calloc(1, sizeof(List)); + if (list == NULL) + { + *error = INSUFFICIENT_MEMORY; + } + return list; +} + +void deleteList(List* list) +{ + ListElement* position = list->head; + while (position != NULL) + { + list->head = list->head->next; + free(position->value); + free(position); + position = list->head; + } + free(list); +} + +void deletePosition(Position* position) +{ + free(position); +} + +void removeFirstElement(List* list, Error* error) +{ + if (*error != NOT_ERROR) + { + return; + } + if (list->head == NULL) + { + *error = EMPTY_LIST; + return; + } + if (list->head == list->tail) + { + list->size = 0; + free(list->head->value); + free(list->head); + list->head = NULL; + list->tail = NULL; + return; + } + ListElement* element = list->head; + list->head = list->head->next; + list->size--; + free(element->value); + free(element); + +} + +Position* first(List* list, Error* error) +{ + if (*error != NOT_ERROR) + { + return NULL; + } + Position* positionFirst = malloc(sizeof(Position)); + if (positionFirst == NULL) + { + *error = EMPTY_LIST; + return NULL; + } + positionFirst->position = list->head; + return positionFirst; +} + +Position* last(List* list, Error* error) +{ + if (*error != NOT_ERROR) + { + return NULL; + } + Position* positionLast = malloc(sizeof(Position)); + if (positionLast == NULL) + { + *error = EMPTY_LIST; + return NULL; + } + positionLast->position = list->tail; + return positionLast; +} + +Position* next(Position* position) +{ + position->position = position->position->next; + return position; +} + +bool isLastElement(Position* position) +{ + return position->position->next == NULL; +} + +int numberOfElements(List* list) +{ + return list->size; +} + +char* getHeadValue(List* list) +{ + if (list->head == NULL) + { + return NULL; + } + return list->head->value; +} + +void add(List* list, const char* value, Error* error) +{ + if (*error != NOT_ERROR) + { + return; + } + if (list->head == NULL) + { + char* valueCopy = calloc(strlen(value) + 1, sizeof(char)); + if (valueCopy == NULL) + { + *error = INSUFFICIENT_MEMORY; + return; + } + strcpy(valueCopy, value); + ListElement* newElement = calloc(1, sizeof(ListElement)); + if (newElement == NULL) + { + free(valueCopy); + *error = INSUFFICIENT_MEMORY; + return; + } + newElement->value = valueCopy; + list->size = 1; + list->head = newElement; + list->tail = newElement; + list->head->numberOfDuplicateValues = 1; + return; + } + ListElement* head = list->head; + while (head != NULL) + { + if (strcmp(value, head->value) == 0) + { + head->numberOfDuplicateValues++; + *error = ELEMENT_REPEATS; + return; + } + head = head->next; + } + if (head == NULL) + { + char* valueCopy = calloc(strlen(value) + 1, sizeof(char)); + if (valueCopy == NULL) + { + *error = INSUFFICIENT_MEMORY; + return; + } + strcpy(valueCopy, value); + ListElement* newElement = calloc(1, sizeof(ListElement)); + if (newElement == NULL) + { + free(valueCopy); + *error = INSUFFICIENT_MEMORY; + return; + } + newElement->value = valueCopy; + list->size++; + list->tail->next = newElement; + list->tail = list->tail->next; + newElement->numberOfDuplicateValues = 1; + } +} + +char* getValue(Position* position) +{ + return position->position->value; +} + +bool isEmpty(List* list) +{ + return list->head == NULL; +} + +bool isOneElement(List* list) +{ + return list->head->next == NULL; +} + +void print(List* list) +{ + ListElement* element = list->head; + while (element != NULL) + { + printf("%s - %d\n", element->value, element->numberOfDuplicateValues); + element = element->next; + } +} + +const char* decodingError(Error error) +{ + if (error == EMPTY_LIST) + { + return "Error in the program"; + } + if (error == INSUFFICIENT_MEMORY) + { + return "Memory not allocated"; + } + return NULL; +} + +bool inList(List* list, const char* value) +{ + ListElement* element = list->head; + while (element != NULL) + { + if (strcmp(value, element->value) == 0) + { + return true; + } + element = element->next; + } + return false; +} \ No newline at end of file diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h new file mode 100644 index 0000000..e77813e --- /dev/null +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h @@ -0,0 +1,59 @@ +#pragma once +#include + +// Structure that represents list +typedef struct List List; + +// This is a structure describing the position of an item in the list. +typedef struct Position Position; + +// Enum type for working with errors +typedef enum Error +{ + NOT_ERROR, + EMPTY_LIST, + INSUFFICIENT_MEMORY, + ELEMENT_REPEATS +} Error; + +// Function for creating a list +List* createList(Error* error); + +// Function for deleting a list +void deleteList(List* list); + +// Function for freeing up memory +void deletePosition(Position* position); + +// Function for adding an item to a list +void add(List* list, const char* value, Error* error); + +// function to find a position to the first element +Position* first(List* list, Error* error); + +// Function for finding a position to the next element +Position* next(Position* position); + +// Function for checking an item for being at the end of the list +bool isLastElement(Position* position); + +// Function for printing a list +void print(List* list); + +// Function for deleting the first element +void removeFirstElement(List* list, Error* error); + +// Function for finding the number of items in the list +int numberOfElements(List* list); + +// Function for checking the emptiness of the list +bool isEmpty(List* list); + +// Function that returns a value for the first element +char* getHeadValue(List* list); + +// Function that returns a value of element +char* getValue(Position* position); + +// Function for error decoding +const char* decodingError(Error error); \ No newline at end of file diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj new file mode 100644 index 0000000..d500241 --- /dev/null +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {abf8d20f-cbdb-4353-9bcc-d9ecc7866f3e} + SinglyLinkedListForHashTable + 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/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj.filters b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj.filters new file mode 100644 index 0000000..950f937 --- /dev/null +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.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/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c new file mode 100644 index 0000000..677718a --- /dev/null +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c @@ -0,0 +1,98 @@ +#include "TestSinglyLinkedListForHashTable.h" +#include "SinglyLinkedListForHashTable.h" +#include + +// Function to check the function that adds an item to the list +bool testAdd() +{ + Error error = NOT_ERROR; + List* newList = createList(&error); + add(newList, "test", &error); + add(newList, "list", &error); + if (error == INSUFFICIENT_MEMORY) + { + deleteList(newList); + return false; + } + const char* firstValue = getHeadValue(newList); + Position* position = first(newList, &error); + if (error == EMPTY_LIST) + { + deleteList(newList); + return false; + } + const char* secondValue = getValue(next(position)); + bool result = strcmp(firstValue, "test") == 0 && strcmp(secondValue, "list") == 0; + deletePosition(position); + deleteList(newList); + return result; +} + +// Function to check the function that deletes the first item in the list +bool testRemoveHead() +{ + Error error = NOT_ERROR; + List* newList = createList(&error); + add(newList, "Hello", &error); + add(newList, "World", &error); + removeFirstElement(newList, &error); + if (error == EMPTY_LIST || error == INSUFFICIENT_MEMORY) + { + deleteList(newList); + return false; + } + const char* value = getHeadValue(newList); + bool result = strcmp(value, "World") == 0; + deleteList(newList); + return result; +} + +// Function for checking the function counting the number of elements +bool testNumberOfElements() +{ + Error error = NOT_ERROR; + List* newList = createList(&error); + add(newList, "Hello", &error); + add(newList, "Merge", &error); + add(newList, "test", &error); + add(newList, "list", &error); + if (error == INSUFFICIENT_MEMORY) + { + deleteList(newList); + return false; + } + const int number = numberOfElements(newList); + deleteList(newList); + return number == 4; +} + +// Function that checks the function that returns the value of the first element +bool testGetValue() +{ + Error error = NOT_ERROR; + List* newList = createList(&error); + add(newList, "Hello", &error); + add(newList, "World", &error); + if (error == INSUFFICIENT_MEMORY) + { + deleteList(newList); + return false; + } + Position* position = first(newList, &error); + if (error == EMPTY_LIST) + { + deleteList(newList); + return false; + } + const char* firstValue = getHeadValue(newList); + const char* secondValue = getValue(next(position)); + bool result = strcmp(firstValue, "Hello") == 0 && strcmp(secondValue, "World") == 0; + deleteList(newList); + deletePosition(position); + return result; +} + +bool allTest() +{ + return testAdd() && testGetValue() && testNumberOfElements() && testRemoveHead(); +} \ No newline at end of file diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h new file mode 100644 index 0000000..737bfba --- /dev/null +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h @@ -0,0 +1,5 @@ +#pragma once +#include + +// A function that combines the results of all tests +bool allTest(); \ No newline at end of file From 0a7f1609b2303c3171b479877ff97354b6be1c29 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 20:44:18 +0300 Subject: [PATCH 03/16] added a function that determines whether an item is in the list --- .../SinglyLinkedListForHashTable.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h index e77813e..f7feae8 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h @@ -56,4 +56,7 @@ char* getHeadValue(List* list); char* getValue(Position* position); // Function for error decoding -const char* decodingError(Error error); \ No newline at end of file +const char* decodingError(Error error); + +// Function to check whether an item is in the list +bool inList(List* list, const char* value); \ No newline at end of file From 95cf48bd8e7c295354b99529872901e403c65693 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 20:55:53 +0300 Subject: [PATCH 04/16] Revert "added a function that determines whether an item is in the list" This reverts commit 0a7f1609b2303c3171b479877ff97354b6be1c29. --- .../SinglyLinkedListForHashTable.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h index f7feae8..e77813e 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h @@ -56,7 +56,4 @@ char* getHeadValue(List* list); char* getValue(Position* position); // Function for error decoding -const char* decodingError(Error error); - -// Function to check whether an item is in the list -bool inList(List* list, const char* value); \ No newline at end of file +const char* decodingError(Error error); \ No newline at end of file From ff784e0096564d4835744c9e66932b03085732d7 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 5 Dec 2021 13:29:50 +0300 Subject: [PATCH 05/16] changed the function for deleting an element --- .../SinglyLinkedListForHashTable.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c index fd6d1cf..8e5d99e 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c @@ -75,6 +75,10 @@ void removeFirstElement(List* list, Error* error) return; } ListElement* element = list->head; + if (element->numberOfDuplicateValues > 1) + { + element->numberOfDuplicateValues--; + } list->head = list->head->next; list->size--; free(element->value); @@ -168,18 +172,18 @@ void add(List* list, const char* value, Error* error) list->head->numberOfDuplicateValues = 1; return; } - ListElement* head = list->head; - while (head != NULL) + ListElement* element = list->head; + while (element != NULL) { - if (strcmp(value, head->value) == 0) + if (strcmp(value, element->value) == 0) { - head->numberOfDuplicateValues++; + element->numberOfDuplicateValues++; *error = ELEMENT_REPEATS; return; } - head = head->next; + element = element->next; } - if (head == NULL) + if (element == NULL) { char* valueCopy = calloc(strlen(value) + 1, sizeof(char)); if (valueCopy == NULL) From 152c6aa44678354df0fc9e31baff6a45346c49da Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 5 Dec 2021 13:55:54 +0300 Subject: [PATCH 06/16] changed the function for deleting an element --- .../SinglyLinkedListForHashTable.c | 37 +++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c index 8e5d99e..107b75b 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c @@ -1,3 +1,4 @@ +#define _CRT_SECURE_NO_WARNINGS #include "SinglyLinkedListForHashTable.h" #include #include @@ -9,7 +10,6 @@ typedef struct List { int size; struct ListElement* head; - struct ListElement* tail; } List; // Structure containing a pointer to the next list item and a value variable for the list items @@ -54,6 +54,11 @@ void deletePosition(Position* position) free(position); } +bool isOneElement(List* list) +{ + return list->head->next == NULL; +} + void removeFirstElement(List* list, Error* error) { if (*error != NOT_ERROR) @@ -65,19 +70,19 @@ void removeFirstElement(List* list, Error* error) *error = EMPTY_LIST; return; } - if (list->head == list->tail) + if (isOneElement(list)) { list->size = 0; free(list->head->value); free(list->head); list->head = NULL; - list->tail = NULL; return; } ListElement* element = list->head; if (element->numberOfDuplicateValues > 1) { element->numberOfDuplicateValues--; + return; } list->head = list->head->next; list->size--; @@ -102,22 +107,6 @@ Position* first(List* list, Error* error) return positionFirst; } -Position* last(List* list, Error* error) -{ - if (*error != NOT_ERROR) - { - return NULL; - } - Position* positionLast = malloc(sizeof(Position)); - if (positionLast == NULL) - { - *error = EMPTY_LIST; - return NULL; - } - positionLast->position = list->tail; - return positionLast; -} - Position* next(Position* position) { position->position = position->position->next; @@ -168,7 +157,6 @@ void add(List* list, const char* value, Error* error) newElement->value = valueCopy; list->size = 1; list->head = newElement; - list->tail = newElement; list->head->numberOfDuplicateValues = 1; return; } @@ -200,9 +188,9 @@ void add(List* list, const char* value, Error* error) return; } newElement->value = valueCopy; + newElement->next = list->head; + list->head = newElement; list->size++; - list->tail->next = newElement; - list->tail = list->tail->next; newElement->numberOfDuplicateValues = 1; } } @@ -217,11 +205,6 @@ bool isEmpty(List* list) return list->head == NULL; } -bool isOneElement(List* list) -{ - return list->head->next == NULL; -} - void print(List* list) { ListElement* element = list->head; From b2733c6e0ef27d0df7a7076f51a8ac4ed139f95b Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 5 Dec 2021 14:18:57 +0300 Subject: [PATCH 07/16] adding functions --- .../SinglyLinkedListForHashTable.c | 14 ++++++++++++++ .../SinglyLinkedListForHashTable.h | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c index 107b75b..2c31e91 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c @@ -240,4 +240,18 @@ bool inList(List* list, const char* value) element = element->next; } return false; +} + +int returnNumberOfDuplicateValues(List* list, const char* value) +{ + ListElement* element = list->head; + while (element != NULL) + { + if (strcmp(value, element->value) == 0) + { + return element->numberOfDuplicateValues; + } + element = element->next; + } + return 0; } \ No newline at end of file diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h index e77813e..486e9ee 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h @@ -56,4 +56,10 @@ char* getHeadValue(List* list); char* getValue(Position* position); // Function for error decoding -const char* decodingError(Error error); \ No newline at end of file +const char* decodingError(Error error); + +// Function for determining the location of an item in the list +bool inList(List* list, const char* value); + +// Function for counting the number of duplicate elements +int returnNumberOfDuplicateValues(List* list, const char* value); \ No newline at end of file From 6407802e58f1de8ac6bb6f22f9636ef1209fcb60 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 5 Dec 2021 15:35:26 +0300 Subject: [PATCH 08/16] changing tests --- .../TestSinglyLinkedListForHashTable.c | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c index 677718a..d6d550c 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c @@ -8,22 +8,10 @@ bool testAdd() Error error = NOT_ERROR; List* newList = createList(&error); add(newList, "test", &error); - add(newList, "list", &error); - if (error == INSUFFICIENT_MEMORY) - { - deleteList(newList); - return false; - } const char* firstValue = getHeadValue(newList); - Position* position = first(newList, &error); - if (error == EMPTY_LIST) - { - deleteList(newList); - return false; - } - const char* secondValue = getValue(next(position)); + add(newList, "list", &error); + const char* secondValue = getHeadValue(newList); bool result = strcmp(firstValue, "test") == 0 && strcmp(secondValue, "list") == 0; - deletePosition(position); deleteList(newList); return result; } @@ -42,7 +30,7 @@ bool testRemoveHead() return false; } const char* value = getHeadValue(newList); - bool result = strcmp(value, "World") == 0; + bool result = strcmp(value, "Hello") == 0; deleteList(newList); return result; } @@ -54,8 +42,8 @@ bool testNumberOfElements() List* newList = createList(&error); add(newList, "Hello", &error); add(newList, "Merge", &error); - add(newList, "test", &error); - add(newList, "list", &error); + add(newList, "test", &error); + add(newList, "list", &error); if (error == INSUFFICIENT_MEMORY) { deleteList(newList); @@ -86,7 +74,7 @@ bool testGetValue() } const char* firstValue = getHeadValue(newList); const char* secondValue = getValue(next(position)); - bool result = strcmp(firstValue, "Hello") == 0 && strcmp(secondValue, "World") == 0; + bool result = strcmp(firstValue, "World") == 0 && strcmp(secondValue, "Hello") == 0; deleteList(newList); deletePosition(position); return result; @@ -94,5 +82,5 @@ bool testGetValue() bool allTest() { - return testAdd() && testGetValue() && testNumberOfElements() && testRemoveHead(); + return testAdd() && testRemoveHead() && testNumberOfElements() && testGetValue(); } \ No newline at end of file From 17ed4b7ebca331a3031a57591b891d3439142903 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Tue, 7 Dec 2021 13:52:38 +0300 Subject: [PATCH 09/16] create list --- Test2/List/List.sln | 31 ++++ Test2/List/List/List.c | 232 +++++++++++++++++++++++++++ Test2/List/List/List.h | 70 ++++++++ Test2/List/List/List.vcxproj | 153 ++++++++++++++++++ Test2/List/List/List.vcxproj.filters | 36 +++++ Test2/List/List/Main.c | 9 ++ Test2/List/List/TestList.c | 98 +++++++++++ Test2/List/List/TestList.h | 5 + 8 files changed, 634 insertions(+) create mode 100644 Test2/List/List.sln create mode 100644 Test2/List/List/List.c create mode 100644 Test2/List/List/List.h create mode 100644 Test2/List/List/List.vcxproj create mode 100644 Test2/List/List/List.vcxproj.filters create mode 100644 Test2/List/List/Main.c create mode 100644 Test2/List/List/TestList.c create mode 100644 Test2/List/List/TestList.h diff --git a/Test2/List/List.sln b/Test2/List/List.sln new file mode 100644 index 0000000..73635b1 --- /dev/null +++ b/Test2/List/List.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}") = "List", "List\List.vcxproj", "{533300D7-FEA4-4761-9777-C29203DD51E2}" +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 + {533300D7-FEA4-4761-9777-C29203DD51E2}.Debug|x64.ActiveCfg = Debug|x64 + {533300D7-FEA4-4761-9777-C29203DD51E2}.Debug|x64.Build.0 = Debug|x64 + {533300D7-FEA4-4761-9777-C29203DD51E2}.Debug|x86.ActiveCfg = Debug|Win32 + {533300D7-FEA4-4761-9777-C29203DD51E2}.Debug|x86.Build.0 = Debug|Win32 + {533300D7-FEA4-4761-9777-C29203DD51E2}.Release|x64.ActiveCfg = Release|x64 + {533300D7-FEA4-4761-9777-C29203DD51E2}.Release|x64.Build.0 = Release|x64 + {533300D7-FEA4-4761-9777-C29203DD51E2}.Release|x86.ActiveCfg = Release|Win32 + {533300D7-FEA4-4761-9777-C29203DD51E2}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C2C67AAA-198F-422F-BABF-C9EB2928E1B4} + EndGlobalSection +EndGlobal diff --git a/Test2/List/List/List.c b/Test2/List/List/List.c new file mode 100644 index 0000000..1845c37 --- /dev/null +++ b/Test2/List/List/List.c @@ -0,0 +1,232 @@ +#include "List.h" +#include +#include +#include +#include + +// Structure containing pointers to the beginning and end of the list +typedef struct List +{ + int size; + struct ListElement* head; + struct ListElement* tail; +} List; + +// Structure containing a pointer to the next list item and a value variable for the list items +typedef struct ListElement +{ + int value; + struct ListElement* next; +} ListElement; + +// Structure containing a pointer to a ListElement +typedef struct Position +{ + ListElement* position; +} Position; + +List* createList() +{ + return calloc(1, sizeof(List)); +} + +void deleteList(List* list) +{ + ListElement* position = list->head; + while (position != NULL) + { + list->head = list->head->next; + free(position); + position = list->head; + } + free(list); +} + +void deletePosition(Position* position) +{ + free(position); +} + +void removeFirstElement(List* list, Error* error) +{ + if (*error != NOT_ERROR) + { + return; + } + if (list->head == NULL) + { + *error = EMPTY_LIST; + return; + } + if (list->head == list->tail) + { + list->size = 0; + free(list->head); + list->head = NULL; + list->tail = NULL; + return; + } + ListElement* element = list->head; + list->head = list->head->next; + list->size--; + free(element); + +} + +Position* first(List* list, Error* error) +{ + if (*error != NOT_ERROR) + { + return NULL; + } + Position* positionFirst = malloc(sizeof(Position)); + if (positionFirst == NULL) + { + *error = EMPTY_LIST; + return NULL; + } + positionFirst->position = list->head; + return positionFirst; +} + +Position* last(List* list, Error* error) +{ + if (*error != NOT_ERROR) + { + return NULL; + } + Position* positionLast = malloc(sizeof(Position)); + if (positionLast == NULL) + { + *error = EMPTY_LIST; + return NULL; + } + positionLast->position = list->tail; + return positionLast; +} + +Position* next(Position* position) +{ + position->position = position->position->next; + return position; +} + +bool isLastElement(Position* position) +{ + return position->position->next == NULL; +} + +int numberOfElements(List* list) +{ + return list->size; +} + +int getHeadValue(List* list) +{ + if (list->head == NULL) + { + return 0; + } + return list->head->value; +} + +int getValue(Position* position) +{ + if (position->position == NULL) + { + return 0; + } + return position->position->value; +} + +void add(List* list, const int value, Error* error) +{ + if (*error != NOT_ERROR) + { + return; + } + ListElement* newElement = calloc(1, sizeof(ListElement)); + if (newElement == NULL) + { + *error = INSUFFICIENT_MEMORY; + return; + } + newElement->value = value; + if (list->head == NULL) + { + list->size = 1; + list->head = newElement; + list->tail = newElement; + return; + } + list->size++; + list->tail->next = newElement; + list->tail = list->tail->next; +} + +bool isEmpty(List* list) +{ + return list->head == NULL; +} + +bool isOneElement(List* list) +{ + return list->head->next == NULL; +} + +void print(List* list) +{ + ListElement* element = list->head; + while (element != NULL) + { + printf("%d ", element->value); + element = element->next; + } +} + +bool compareList(List* firstList, List* secondList) +{ + ListElement* firstElement = firstList->head; + ListElement* secondElement = secondList->head; + if (numberOfElements(firstList) != numberOfElements(secondList)) + { + return false; + } + while (firstElement != NULL) + { + if (firstElement->value != secondElement->value) + { + return false; + } + firstElement = firstElement->next; + secondElement = secondElement->next; + } + return true; +} + +const char* decodingError(Error error) +{ + if (error == EMPTY_LIST) + { + return "Error in the program"; + } + if (error == INSUFFICIENT_MEMORY) + { + return "Memory not allocated"; + } + return NULL; +} + +bool inList(List* list, int value) +{ + ListElement* element = list->head; + while (element != NULL) + { + if (element->value == value) + { + return true; + } + element = element->next; + } + return false; +} \ No newline at end of file diff --git a/Test2/List/List/List.h b/Test2/List/List/List.h new file mode 100644 index 0000000..b20b16b --- /dev/null +++ b/Test2/List/List/List.h @@ -0,0 +1,70 @@ +#pragma once +#include + +// Structure that represents list +typedef struct List List; + +// This is a structure describing the position of an item in the list. +typedef struct Position Position; + +// Enum type for working with errors +typedef enum Error +{ + NOT_ERROR, + EMPTY_LIST, + INSUFFICIENT_MEMORY +} Error; + +// Function for creating a list +List* createList(); + +// Function for deleting a list +void deleteList(List* list); + +// Function for freeing up memory +void deletePosition(Position* position); + +// Function for adding an item to a list +void add(List* list, const int firstValue, Error* error); + +// function to find a position to the first element +Position* first(List* list, Error* error); + +// Function for finding a position to the next element +Position* next(Position* position); + +// Function for checking an item for being at the end of the list +bool isLastElement(Position* position); + +// Function for printing a list +void print(List* list); + +// Function for deleting the first element +void removeFirstElement(List* list, Error* error); + +// Function for finding the number of items in the list +int numberOfElements(List* list); + +// Function for checking the emptiness of the list +bool isEmpty(List* list); + +// Function for checking the list for the content of a single element +bool isOneElement(List* list); + +// Function that returns a value for the first element +int getHeadValue(List* list); + +// Function for finding a position to the last element +Position* last(List* list, Error* error); + +// Returns the value of any element +int getValue(Position* position); + +// Function for comparing lists +bool compareList(List* firstList, List* secondList); + +// Function for error decoding +const char* decodingError(Error error); + +// Function that checks whether an item is contained in a list +bool inList(List* list, int value); \ No newline at end of file diff --git a/Test2/List/List/List.vcxproj b/Test2/List/List/List.vcxproj new file mode 100644 index 0000000..97ecfea --- /dev/null +++ b/Test2/List/List/List.vcxproj @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {533300d7-fea4-4761-9777-c29203dd51e2} + List + 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/Test2/List/List/List.vcxproj.filters b/Test2/List/List/List.vcxproj.filters new file mode 100644 index 0000000..9c7580a --- /dev/null +++ b/Test2/List/List/List.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/Test2/List/List/Main.c b/Test2/List/List/Main.c new file mode 100644 index 0000000..6ffb51a --- /dev/null +++ b/Test2/List/List/Main.c @@ -0,0 +1,9 @@ +#include "TestList.h" + +int main() +{ + if (!allTest()) + { + return -1; + } +} \ No newline at end of file diff --git a/Test2/List/List/TestList.c b/Test2/List/List/TestList.c new file mode 100644 index 0000000..22e2b55 --- /dev/null +++ b/Test2/List/List/TestList.c @@ -0,0 +1,98 @@ +#include "TestList.h" +#include "List.h" +#include + +// Function to check the function that adds an item to the list +bool testAdd() +{ + Error error = NOT_ERROR; + List* newList = createList(); + add(newList, 12, &error); + add(newList, -23, &error); + if (error == INSUFFICIENT_MEMORY) + { + deleteList(newList); + return false; + } + const int firstValue = getHeadValue(newList); + Position* position = first(newList, &error); + if (error == EMPTY_LIST) + { + deleteList(newList); + return false; + } + next(position); + const int secondValue = getValue(position); + bool result = firstValue == 12 && secondValue == -23; + deletePosition(position); + deleteList(newList); + return result; +} + +// Function to check the function that deletes the first item in the list +bool testRemoveHead() +{ + Error error = NOT_ERROR; + List* newList = createList(); + add(newList, 123, &error); + add(newList, -34, &error); + removeFirstElement(newList, &error); + if (error == EMPTY_LIST || error == INSUFFICIENT_MEMORY) + { + deleteList(newList); + return false; + } + const int headOfListValue = getHeadValue(newList); + bool result = headOfListValue == -34; + deleteList(newList); + return result; +} + +// Function for checking the function counting the number of elements +bool testNumberOfElements() +{ + List* newList = createList(); + Error error = NOT_ERROR; + add(newList, 123, &error); + add(newList, -32, &error); + add(newList, 47, &error); + add(newList, 24, &error); + if (error == INSUFFICIENT_MEMORY) + { + deleteList(newList); + return false; + } + const int number = numberOfElements(newList); + deleteList(newList); + return number == 4; +} + +// Function that checks the function that returns the value of the first element +bool testGetValue() +{ + List* newList = createList(); + Error error = NOT_ERROR; + add(newList, 123, &error); + add(newList, -44, &error); + if (error == INSUFFICIENT_MEMORY) + { + deleteList(newList); + return false; + } + const int firstValue = getHeadValue(newList); + Position* position = first(newList, &error); + if (error != NOT_ERROR) + { + return false; + } + const int secondValue = getValue(next(position)); + bool result = firstValue == 123 && secondValue == -44; + deletePosition(position); + deleteList(newList); + return result; +} + +bool allTest() +{ + return testAdd() && testGetValue() && testNumberOfElements() && testRemoveHead(); +} \ No newline at end of file diff --git a/Test2/List/List/TestList.h b/Test2/List/List/TestList.h new file mode 100644 index 0000000..737bfba --- /dev/null +++ b/Test2/List/List/TestList.h @@ -0,0 +1,5 @@ +#pragma once +#include + +// A function that combines the results of all tests +bool allTest(); \ No newline at end of file From 7b54f1e588f315833ad3f53ebf6cba7be48eb6bf Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Tue, 7 Dec 2021 14:26:46 +0300 Subject: [PATCH 10/16] writing all functions --- Test2/Task1/Task1.sln | 31 +++++ Test2/Task1/Task1/File.txt | 1 + Test2/Task1/Task1/Main.c | 21 ++++ Test2/Task1/Task1/MergeList.c | 28 +++++ Test2/Task1/Task1/MergeList.h | 6 + Test2/Task1/Task1/Result.txt | 1 + Test2/Task1/Task1/Task1.vcxproj | 157 ++++++++++++++++++++++++ Test2/Task1/Task1/Task1.vcxproj.filters | 48 ++++++++ Test2/Task1/Task1/Test.txt | 1 + Test2/Task1/Task1/TestWorkWithFile.c | 34 +++++ Test2/Task1/Task1/TestWorkWithFile.h | 5 + Test2/Task1/Task1/WorkWithFile.c | 60 +++++++++ Test2/Task1/Task1/WorkWithFile.h | 8 ++ 13 files changed, 401 insertions(+) create mode 100644 Test2/Task1/Task1.sln create mode 100644 Test2/Task1/Task1/File.txt create mode 100644 Test2/Task1/Task1/Main.c create mode 100644 Test2/Task1/Task1/MergeList.c create mode 100644 Test2/Task1/Task1/MergeList.h create mode 100644 Test2/Task1/Task1/Result.txt create mode 100644 Test2/Task1/Task1/Task1.vcxproj create mode 100644 Test2/Task1/Task1/Task1.vcxproj.filters create mode 100644 Test2/Task1/Task1/Test.txt create mode 100644 Test2/Task1/Task1/TestWorkWithFile.c create mode 100644 Test2/Task1/Task1/TestWorkWithFile.h create mode 100644 Test2/Task1/Task1/WorkWithFile.c create mode 100644 Test2/Task1/Task1/WorkWithFile.h diff --git a/Test2/Task1/Task1.sln b/Test2/Task1/Task1.sln new file mode 100644 index 0000000..9b9d813 --- /dev/null +++ b/Test2/Task1/Task1.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}") = "Task1", "Task1\Task1.vcxproj", "{90209686-C141-4D06-91B8-9718A8A7315D}" +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 + {90209686-C141-4D06-91B8-9718A8A7315D}.Debug|x64.ActiveCfg = Debug|x64 + {90209686-C141-4D06-91B8-9718A8A7315D}.Debug|x64.Build.0 = Debug|x64 + {90209686-C141-4D06-91B8-9718A8A7315D}.Debug|x86.ActiveCfg = Debug|Win32 + {90209686-C141-4D06-91B8-9718A8A7315D}.Debug|x86.Build.0 = Debug|Win32 + {90209686-C141-4D06-91B8-9718A8A7315D}.Release|x64.ActiveCfg = Release|x64 + {90209686-C141-4D06-91B8-9718A8A7315D}.Release|x64.Build.0 = Release|x64 + {90209686-C141-4D06-91B8-9718A8A7315D}.Release|x86.ActiveCfg = Release|Win32 + {90209686-C141-4D06-91B8-9718A8A7315D}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AE72510F-467F-44EE-87D1-638542C499FF} + EndGlobalSection +EndGlobal diff --git a/Test2/Task1/Task1/File.txt b/Test2/Task1/Task1/File.txt new file mode 100644 index 0000000..988f640 --- /dev/null +++ b/Test2/Task1/Task1/File.txt @@ -0,0 +1 @@ +1 45 5 3 9 5 2 4 2 1 10 34 6 8 \ No newline at end of file diff --git a/Test2/Task1/Task1/Main.c b/Test2/Task1/Task1/Main.c new file mode 100644 index 0000000..b392897 --- /dev/null +++ b/Test2/Task1/Task1/Main.c @@ -0,0 +1,21 @@ +#include "TestWorkWithFile.h" +#include "WorkWithFile.h" +#include "../../List/List/List.h" + +int main() +{ + if (!testWorkWithFile()) + { + return -1; + } + Error error = NOT_ERROR; + int a = 4; + int b = 10; + List* firstList = readFile("File.txt", a, b); + int writeResult = writeFile("Result.txt", firstList); + if (writeResult == -2) + { + printf("could not open the file"); + } + deleteList(firstList); +} \ No newline at end of file diff --git a/Test2/Task1/Task1/MergeList.c b/Test2/Task1/Task1/MergeList.c new file mode 100644 index 0000000..2e844f5 --- /dev/null +++ b/Test2/Task1/Task1/MergeList.c @@ -0,0 +1,28 @@ +#include "MergeList.h" +#include +#include + +List* merge(List* firstList, List* secondList, Error* error) +{ + List* sortedList = createList(); + while (!isEmpty(firstList)) + { + add(sortedList, getHeadValue(firstList), error); + removeFirstElement(firstList, error); + } + while (!isEmpty(secondList)) + { + add(sortedList, getHeadValue(secondList), error); + removeFirstElement(secondList, error); + } + if (*error == EMPTY_LIST || *error == INSUFFICIENT_MEMORY) + { + deleteList(sortedList); + deleteList(firstList); + deleteList(secondList); + return NULL; + } + free(firstList); + free(secondList); + return sortedList; +} \ No newline at end of file diff --git a/Test2/Task1/Task1/MergeList.h b/Test2/Task1/Task1/MergeList.h new file mode 100644 index 0000000..417de27 --- /dev/null +++ b/Test2/Task1/Task1/MergeList.h @@ -0,0 +1,6 @@ +#pragma once +#include "../../List/List/List.h" + +// Function for merging lists +List* merge(List* firstList, List* secondList, Error* error); + diff --git a/Test2/Task1/Task1/Result.txt b/Test2/Task1/Task1/Result.txt new file mode 100644 index 0000000..54bd23a --- /dev/null +++ b/Test2/Task1/Task1/Result.txt @@ -0,0 +1 @@ +1 3 2 2 1 5 9 5 4 10 6 8 45 34 \ No newline at end of file diff --git a/Test2/Task1/Task1/Task1.vcxproj b/Test2/Task1/Task1/Task1.vcxproj new file mode 100644 index 0000000..57fb9d3 --- /dev/null +++ b/Test2/Task1/Task1/Task1.vcxproj @@ -0,0 +1,157 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {90209686-c141-4d06-91b8-9718a8a7315d} + Task1 + 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/Test2/Task1/Task1/Task1.vcxproj.filters b/Test2/Task1/Task1/Task1.vcxproj.filters new file mode 100644 index 0000000..dbbd13d --- /dev/null +++ b/Test2/Task1/Task1/Task1.vcxproj.filters @@ -0,0 +1,48 @@ + + + + + {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/Test2/Task1/Task1/Test.txt b/Test2/Task1/Task1/Test.txt new file mode 100644 index 0000000..b09fdef --- /dev/null +++ b/Test2/Task1/Task1/Test.txt @@ -0,0 +1 @@ +2 6 3 97 23 12 1143 23 3 76 123 908 -12 570 \ No newline at end of file diff --git a/Test2/Task1/Task1/TestWorkWithFile.c b/Test2/Task1/Task1/TestWorkWithFile.c new file mode 100644 index 0000000..676a9f3 --- /dev/null +++ b/Test2/Task1/Task1/TestWorkWithFile.c @@ -0,0 +1,34 @@ +#include "TestWorkWithFile.h" +#include "WorkWithFile.h" +#include "../../List/List/List.h" + +bool testWorkWithFile() +{ + Error error = NOT_ERROR; + List* list = readFile("Test.txt", 5, 569); + List* firstList = createList(); + add(firstList, 2, &error); + add(firstList, 3, &error); + add(firstList, 3, &error); + add(firstList, -12, &error); + add(firstList, 6, &error); + add(firstList, 97, &error); + add(firstList, 23, &error); + add(firstList, 12, &error); + add(firstList, 23, &error); + add(firstList, 76, &error); + add(firstList, 123, &error); + add(firstList, 1143, &error); + add(firstList, 908, &error); + add(firstList, 570, &error); + if (error != NOT_ERROR) + { + deleteList(firstList); + deleteList(list); + return false; + } + bool result = compareList(firstList, list); + deleteList(firstList); + deleteList(list); + return result; +} \ No newline at end of file diff --git a/Test2/Task1/Task1/TestWorkWithFile.h b/Test2/Task1/Task1/TestWorkWithFile.h new file mode 100644 index 0000000..f6de8cb --- /dev/null +++ b/Test2/Task1/Task1/TestWorkWithFile.h @@ -0,0 +1,5 @@ +#pragma once +#include + +// Function for checking functions for working with a file +bool testWorkWithFile(); diff --git a/Test2/Task1/Task1/WorkWithFile.c b/Test2/Task1/Task1/WorkWithFile.c new file mode 100644 index 0000000..0e6776d --- /dev/null +++ b/Test2/Task1/Task1/WorkWithFile.c @@ -0,0 +1,60 @@ +#include "WorkWithFile.h" +#include +#include "MergeList.h" + +List* readFile(const char* filename, int a, int b) +{ + FILE* file = fopen(filename, "r"); + if (file == NULL) + { + return NULL; + } + List* result = createList(); + List* secondList = createList(); + List* thirdList = createList(); + Error error = NOT_ERROR; + while (!feof(file)) + { + int temporary = 0; + const int readBytes = fscanf(file, "%d", &temporary); + if (readBytes < 0) + { + break; + } + if (temporary < a) + { + add(result, temporary, &error); + } + else if (temporary > b) + { + add(thirdList, temporary, &error); + } + else + { + add(secondList, temporary, &error); + + } + } + fclose(file); + result = merge(result, merge(secondList, thirdList, &error), &error); + return result; +} + +int writeFile(const char* fileToWrite, List* list) +{ + FILE* file = fopen(fileToWrite, "w"); + if (file == NULL) + { + return -2; + } + Error error = NOT_ERROR; + Position* position = first(list, &error); + for (int i = 0; i < numberOfElements(list); i++) + { + fprintf(file, "%d ", getValue(position)); + next(position); + } + deletePosition(position); + fclose(file); + return 0; +} \ No newline at end of file diff --git a/Test2/Task1/Task1/WorkWithFile.h b/Test2/Task1/Task1/WorkWithFile.h new file mode 100644 index 0000000..edc9cb4 --- /dev/null +++ b/Test2/Task1/Task1/WorkWithFile.h @@ -0,0 +1,8 @@ +#pragma once +#include "../../List/List/List.h" + +// Function for checking functions for working with a file +List* readFile(const char* filename, int a, int b); + +// Function for writing to a file +int writeFile(const char* fileToWrite, List* list); \ No newline at end of file From 3bde7c76649d49a1c8ca90c369171766093c1b3d Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Tue, 7 Dec 2021 14:28:22 +0300 Subject: [PATCH 11/16] fixed bugs --- Test2/Task1/Task1/Main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Test2/Task1/Task1/Main.c b/Test2/Task1/Task1/Main.c index b392897..407520f 100644 --- a/Test2/Task1/Task1/Main.c +++ b/Test2/Task1/Task1/Main.c @@ -1,6 +1,7 @@ #include "TestWorkWithFile.h" #include "WorkWithFile.h" #include "../../List/List/List.h" +#include int main() { @@ -12,6 +13,10 @@ int main() int a = 4; int b = 10; List* firstList = readFile("File.txt", a, b); + if (firstList == NULL) + { + return -1; + } int writeResult = writeFile("Result.txt", firstList); if (writeResult == -2) { From 0fa32e14ee8fef4a6d10f5ab2fad82fcd17a16a9 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Tue, 7 Dec 2021 14:32:15 +0300 Subject: [PATCH 12/16] add comments --- Test2/Task1/Task1/Main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Test2/Task1/Task1/Main.c b/Test2/Task1/Task1/Main.c index 407520f..182e906 100644 --- a/Test2/Task1/Task1/Main.c +++ b/Test2/Task1/Task1/Main.c @@ -10,6 +10,7 @@ int main() return -1; } Error error = NOT_ERROR; + // as a and b, you can take any numbers, 4 and 10 - just an example int a = 4; int b = 10; List* firstList = readFile("File.txt", a, b); From 6881113d195ae01a1feed108cd5ffeffaa69d9dd Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Tue, 7 Dec 2021 15:22:27 +0300 Subject: [PATCH 13/16] fixed bugs --- Test2/Task1/Task1/Main.c | 11 ++++++++--- Test2/Task1/Task1/TestWorkWithFile.c | 7 ++++++- Test2/Task1/Task1/WorkWithFile.c | 10 +++++++++- Test2/Task1/Task1/WorkWithFile.h | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Test2/Task1/Task1/Main.c b/Test2/Task1/Task1/Main.c index 182e906..4f0d11f 100644 --- a/Test2/Task1/Task1/Main.c +++ b/Test2/Task1/Task1/Main.c @@ -11,9 +11,14 @@ int main() } Error error = NOT_ERROR; // as a and b, you can take any numbers, 4 and 10 - just an example - int a = 4; - int b = 10; - List* firstList = readFile("File.txt", a, b); + const int a = 4; + const int b = 10; + int check = 0; + List* firstList = readFile("File.txt", a, b, &check); + if (check != 0) + { + return -1; + } if (firstList == NULL) { return -1; diff --git a/Test2/Task1/Task1/TestWorkWithFile.c b/Test2/Task1/Task1/TestWorkWithFile.c index 676a9f3..01d1b67 100644 --- a/Test2/Task1/Task1/TestWorkWithFile.c +++ b/Test2/Task1/Task1/TestWorkWithFile.c @@ -5,7 +5,12 @@ bool testWorkWithFile() { Error error = NOT_ERROR; - List* list = readFile("Test.txt", 5, 569); + int check = 0; + List* list = readFile("Test.txt", 5, 569, &check); + if (check != 0) + { + return false; + } List* firstList = createList(); add(firstList, 2, &error); add(firstList, 3, &error); diff --git a/Test2/Task1/Task1/WorkWithFile.c b/Test2/Task1/Task1/WorkWithFile.c index 0e6776d..004b0ea 100644 --- a/Test2/Task1/Task1/WorkWithFile.c +++ b/Test2/Task1/Task1/WorkWithFile.c @@ -2,7 +2,7 @@ #include #include "MergeList.h" -List* readFile(const char* filename, int a, int b) +List* readFile(const char* filename, int a, int b, int* check) { FILE* file = fopen(filename, "r"); if (file == NULL) @@ -35,6 +35,14 @@ List* readFile(const char* filename, int a, int b) } } + if (error != NOT_ERROR) + { + deleteList(result); + deleteList(thirdList); + deleteList(secondList); + *check = 3; + return NULL; + } fclose(file); result = merge(result, merge(secondList, thirdList, &error), &error); return result; diff --git a/Test2/Task1/Task1/WorkWithFile.h b/Test2/Task1/Task1/WorkWithFile.h index edc9cb4..7586058 100644 --- a/Test2/Task1/Task1/WorkWithFile.h +++ b/Test2/Task1/Task1/WorkWithFile.h @@ -2,7 +2,7 @@ #include "../../List/List/List.h" // Function for checking functions for working with a file -List* readFile(const char* filename, int a, int b); +List* readFile(const char* filename, int a, int b, int* check); // Function for writing to a file int writeFile(const char* fileToWrite, List* list); \ No newline at end of file From a9c8916bab78d62a28dac63df90c32df8bb9405c Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Wed, 8 Dec 2021 12:03:33 +0300 Subject: [PATCH 14/16] changing the function to remove an item from the list --- .../SinglyLinkedListForHashTable.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c index 2c31e91..1e73ecd 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c @@ -70,7 +70,7 @@ void removeFirstElement(List* list, Error* error) *error = EMPTY_LIST; return; } - if (isOneElement(list)) + if (isOneElement(list) && list->head->numberOfDuplicateValues == 1) { list->size = 0; free(list->head->value); @@ -113,11 +113,6 @@ Position* next(Position* position) return position; } -bool isLastElement(Position* position) -{ - return position->position->next == NULL; -} - int numberOfElements(List* list) { return list->size; From ddc85b0fd63405af6463890f9809a5be25d15a14 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Tue, 14 Dec 2021 11:52:23 +0300 Subject: [PATCH 15/16] a function has been written to determine the correctness of the expression and tests for it --- Test3/Expression/Expression.sln | 31 ++++ Test3/Expression/Expression/Expression.c | 111 +++++++++++++ Test3/Expression/Expression/Expression.h | 5 + .../Expression/Expression/Expression.vcxproj | 153 ++++++++++++++++++ .../Expression/Expression.vcxproj.filters | 36 +++++ Test3/Expression/Expression/Main.c | 21 +++ Test3/Expression/Expression/Test.c | 9 ++ Test3/Expression/Expression/Test.h | 5 + 8 files changed, 371 insertions(+) create mode 100644 Test3/Expression/Expression.sln create mode 100644 Test3/Expression/Expression/Expression.c create mode 100644 Test3/Expression/Expression/Expression.h create mode 100644 Test3/Expression/Expression/Expression.vcxproj create mode 100644 Test3/Expression/Expression/Expression.vcxproj.filters create mode 100644 Test3/Expression/Expression/Main.c create mode 100644 Test3/Expression/Expression/Test.c create mode 100644 Test3/Expression/Expression/Test.h diff --git a/Test3/Expression/Expression.sln b/Test3/Expression/Expression.sln new file mode 100644 index 0000000..c46bd17 --- /dev/null +++ b/Test3/Expression/Expression.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}") = "Expression", "Expression\Expression.vcxproj", "{1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}" +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 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Debug|x64.ActiveCfg = Debug|x64 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Debug|x64.Build.0 = Debug|x64 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Debug|x86.ActiveCfg = Debug|Win32 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Debug|x86.Build.0 = Debug|Win32 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Release|x64.ActiveCfg = Release|x64 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Release|x64.Build.0 = Release|x64 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Release|x86.ActiveCfg = Release|Win32 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {26C5BCF6-7030-442A-9BEA-332D45DD4311} + EndGlobalSection +EndGlobal diff --git a/Test3/Expression/Expression/Expression.c b/Test3/Expression/Expression/Expression.c new file mode 100644 index 0000000..50d6a37 --- /dev/null +++ b/Test3/Expression/Expression/Expression.c @@ -0,0 +1,111 @@ +#include "Expression.h" +#include +#include +#include + +bool isDigit(char symbol) +{ + return symbol >= '0' && symbol <= '9'; +} + +bool isTheStringAGroup(char* string) +{ + const int stringLength = strlen(string); + int state = 0; + for (int i = 0; i < stringLength + 1; i++) + { + switch (state) + { + case 0: + { + if (isDigit(string[i])) + { + state = 1; + break; + } + return false; + } + case 1: + { + if (isDigit(string[i])) + { + state = 2; + break; + } + return false; + } + case 2: + { + if (string[i] == '.') + { + state = 3; + break; + } + return false; + } + case 3: + { + if (string[i] == 'B' || string[i] == 'M' || string[i] == 'S') + { + state = 4; + break; + } + return false; + } + case 4: + { + if (isDigit(string[i])) + { + state = 5; + break; + } + return false; + } + case 5: + { + if (isDigit(string[i])) + { + state = 6; + break; + } + return false; + } + case 6: + { + if (string[i] == '-') + { + state = 7; + break; + } + return false; + } + case 7: + { + if (string[i] == 'm') + { + state = 8; + break; + } + return false; + } + case 8: + { + if (string[i] == 'm') + { + state = 9; + break; + } + return false; + } + case 9: + { + if (string[i] == '\0') + { + return true; + } + return false; + } + } + } + return false; +} \ No newline at end of file diff --git a/Test3/Expression/Expression/Expression.h b/Test3/Expression/Expression/Expression.h new file mode 100644 index 0000000..d5d17ed --- /dev/null +++ b/Test3/Expression/Expression/Expression.h @@ -0,0 +1,5 @@ +#pragma once +#include + +// A function to check whether a string is a valid group number on a matmech +bool isTheStringAGroup(char* string); diff --git a/Test3/Expression/Expression/Expression.vcxproj b/Test3/Expression/Expression/Expression.vcxproj new file mode 100644 index 0000000..3f10d44 --- /dev/null +++ b/Test3/Expression/Expression/Expression.vcxproj @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {1d7bbe92-73bc-4122-94cd-0ad66fefd9ba} + Expression + 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/Test3/Expression/Expression/Expression.vcxproj.filters b/Test3/Expression/Expression/Expression.vcxproj.filters new file mode 100644 index 0000000..6fa1179 --- /dev/null +++ b/Test3/Expression/Expression/Expression.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/Test3/Expression/Expression/Main.c b/Test3/Expression/Expression/Main.c new file mode 100644 index 0000000..0423918 --- /dev/null +++ b/Test3/Expression/Expression/Main.c @@ -0,0 +1,21 @@ +#include "Expression.h" +#include "Test.h" +#include + +int main() +{ + if (!testIsTheStringAGroup()) + { + printf("test failed"); + return -1; + } + char string[1000] = { '\0' }; + printf("enter the line:\n"); + scanf_s("%s", string, (unsigned)sizeof(string)); + if (!isTheStringAGroup(string)) + { + printf("the string is not a valid group number on the mathmech"); + return -1; + } + printf("the string is the correct group number on the matmech"); +} \ No newline at end of file diff --git a/Test3/Expression/Expression/Test.c b/Test3/Expression/Expression/Test.c new file mode 100644 index 0000000..b249945 --- /dev/null +++ b/Test3/Expression/Expression/Test.c @@ -0,0 +1,9 @@ +#include "Test.h" +#include "Expression.h" + +bool testIsTheStringAGroup() +{ + return isTheStringAGroup("21.B10-mm") && !isTheStringAGroup("21.B10mm") + && isTheStringAGroup("12.M07-mm") && !isTheStringAGroup("12.M007-mu") + && isTheStringAGroup("45.S12-mm") && !isTheStringAGroup("12.S.12-mM"); +} \ No newline at end of file diff --git a/Test3/Expression/Expression/Test.h b/Test3/Expression/Expression/Test.h new file mode 100644 index 0000000..a0d6d64 --- /dev/null +++ b/Test3/Expression/Expression/Test.h @@ -0,0 +1,5 @@ +#pragma once +#include + +// Function for checking a function that checks whether a string is a valid group number on a matmech +bool testIsTheStringAGroup(); From 064f4eef3aab4db58d23ea605e85efc554b90a0a Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Tue, 14 Dec 2021 12:41:07 +0300 Subject: [PATCH 16/16] task3 --- FinalTest/Expression/Expression.sln | 31 ++++ FinalTest/Expression/Expression/Expression.c | 111 +++++++++++++ FinalTest/Expression/Expression/Expression.h | 5 + .../Expression/Expression/Expression.vcxproj | 153 ++++++++++++++++++ .../Expression/Expression.vcxproj.filters | 36 +++++ FinalTest/Expression/Expression/Main.c | 21 +++ FinalTest/Expression/Expression/Test.c | 9 ++ FinalTest/Expression/Expression/Test.h | 5 + 8 files changed, 371 insertions(+) create mode 100644 FinalTest/Expression/Expression.sln create mode 100644 FinalTest/Expression/Expression/Expression.c create mode 100644 FinalTest/Expression/Expression/Expression.h create mode 100644 FinalTest/Expression/Expression/Expression.vcxproj create mode 100644 FinalTest/Expression/Expression/Expression.vcxproj.filters create mode 100644 FinalTest/Expression/Expression/Main.c create mode 100644 FinalTest/Expression/Expression/Test.c create mode 100644 FinalTest/Expression/Expression/Test.h diff --git a/FinalTest/Expression/Expression.sln b/FinalTest/Expression/Expression.sln new file mode 100644 index 0000000..c46bd17 --- /dev/null +++ b/FinalTest/Expression/Expression.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}") = "Expression", "Expression\Expression.vcxproj", "{1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}" +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 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Debug|x64.ActiveCfg = Debug|x64 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Debug|x64.Build.0 = Debug|x64 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Debug|x86.ActiveCfg = Debug|Win32 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Debug|x86.Build.0 = Debug|Win32 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Release|x64.ActiveCfg = Release|x64 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Release|x64.Build.0 = Release|x64 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Release|x86.ActiveCfg = Release|Win32 + {1D7BBE92-73BC-4122-94CD-0AD66FEFD9BA}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {26C5BCF6-7030-442A-9BEA-332D45DD4311} + EndGlobalSection +EndGlobal diff --git a/FinalTest/Expression/Expression/Expression.c b/FinalTest/Expression/Expression/Expression.c new file mode 100644 index 0000000..50d6a37 --- /dev/null +++ b/FinalTest/Expression/Expression/Expression.c @@ -0,0 +1,111 @@ +#include "Expression.h" +#include +#include +#include + +bool isDigit(char symbol) +{ + return symbol >= '0' && symbol <= '9'; +} + +bool isTheStringAGroup(char* string) +{ + const int stringLength = strlen(string); + int state = 0; + for (int i = 0; i < stringLength + 1; i++) + { + switch (state) + { + case 0: + { + if (isDigit(string[i])) + { + state = 1; + break; + } + return false; + } + case 1: + { + if (isDigit(string[i])) + { + state = 2; + break; + } + return false; + } + case 2: + { + if (string[i] == '.') + { + state = 3; + break; + } + return false; + } + case 3: + { + if (string[i] == 'B' || string[i] == 'M' || string[i] == 'S') + { + state = 4; + break; + } + return false; + } + case 4: + { + if (isDigit(string[i])) + { + state = 5; + break; + } + return false; + } + case 5: + { + if (isDigit(string[i])) + { + state = 6; + break; + } + return false; + } + case 6: + { + if (string[i] == '-') + { + state = 7; + break; + } + return false; + } + case 7: + { + if (string[i] == 'm') + { + state = 8; + break; + } + return false; + } + case 8: + { + if (string[i] == 'm') + { + state = 9; + break; + } + return false; + } + case 9: + { + if (string[i] == '\0') + { + return true; + } + return false; + } + } + } + return false; +} \ No newline at end of file diff --git a/FinalTest/Expression/Expression/Expression.h b/FinalTest/Expression/Expression/Expression.h new file mode 100644 index 0000000..d5d17ed --- /dev/null +++ b/FinalTest/Expression/Expression/Expression.h @@ -0,0 +1,5 @@ +#pragma once +#include + +// A function to check whether a string is a valid group number on a matmech +bool isTheStringAGroup(char* string); diff --git a/FinalTest/Expression/Expression/Expression.vcxproj b/FinalTest/Expression/Expression/Expression.vcxproj new file mode 100644 index 0000000..3f10d44 --- /dev/null +++ b/FinalTest/Expression/Expression/Expression.vcxproj @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {1d7bbe92-73bc-4122-94cd-0ad66fefd9ba} + Expression + 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/FinalTest/Expression/Expression/Expression.vcxproj.filters b/FinalTest/Expression/Expression/Expression.vcxproj.filters new file mode 100644 index 0000000..6fa1179 --- /dev/null +++ b/FinalTest/Expression/Expression/Expression.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/FinalTest/Expression/Expression/Main.c b/FinalTest/Expression/Expression/Main.c new file mode 100644 index 0000000..0423918 --- /dev/null +++ b/FinalTest/Expression/Expression/Main.c @@ -0,0 +1,21 @@ +#include "Expression.h" +#include "Test.h" +#include + +int main() +{ + if (!testIsTheStringAGroup()) + { + printf("test failed"); + return -1; + } + char string[1000] = { '\0' }; + printf("enter the line:\n"); + scanf_s("%s", string, (unsigned)sizeof(string)); + if (!isTheStringAGroup(string)) + { + printf("the string is not a valid group number on the mathmech"); + return -1; + } + printf("the string is the correct group number on the matmech"); +} \ No newline at end of file diff --git a/FinalTest/Expression/Expression/Test.c b/FinalTest/Expression/Expression/Test.c new file mode 100644 index 0000000..b249945 --- /dev/null +++ b/FinalTest/Expression/Expression/Test.c @@ -0,0 +1,9 @@ +#include "Test.h" +#include "Expression.h" + +bool testIsTheStringAGroup() +{ + return isTheStringAGroup("21.B10-mm") && !isTheStringAGroup("21.B10mm") + && isTheStringAGroup("12.M07-mm") && !isTheStringAGroup("12.M007-mu") + && isTheStringAGroup("45.S12-mm") && !isTheStringAGroup("12.S.12-mM"); +} \ No newline at end of file diff --git a/FinalTest/Expression/Expression/Test.h b/FinalTest/Expression/Expression/Test.h new file mode 100644 index 0000000..a0d6d64 --- /dev/null +++ b/FinalTest/Expression/Expression/Test.h @@ -0,0 +1,5 @@ +#pragma once +#include + +// Function for checking a function that checks whether a string is a valid group number on a matmech +bool testIsTheStringAGroup();