From f3b2155d4842ff7d30b3816d03026a3733530055 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 26 Nov 2021 13:09:43 +0300 Subject: [PATCH 01/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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 a9c8916bab78d62a28dac63df90c32df8bb9405c Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Wed, 8 Dec 2021 12:03:33 +0300 Subject: [PATCH 09/12] 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 d45246e3d3417a756700aed96697bd2c4fe73854 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 12 Dec 2021 22:42:23 +0300 Subject: [PATCH 10/12] a prefix function has been written to implement the KMP algorithm --- ...th\342\200\223Morris\342\200\223Pratt.sln" | 31 ++++ .../KMP.c" | 66 ++++++++ .../KMP.h" | 7 + ...42\200\223Morris\342\200\223Pratt.vcxproj" | 157 ++++++++++++++++++ ...23Morris\342\200\223Pratt.vcxproj.filters" | 48 ++++++ .../Main.c" | 49 ++++++ .../ReadFile.c" | 40 +++++ .../ReadFile.h" | 4 + .../ReadString.c" | 36 ++++ .../ReadString.h" | 4 + .../Test.txt" | 1 + .../TestKMP.c" | 44 +++++ .../TestKMP.h" | 5 + .../Text.txt" | 1 + 14 files changed, 493 insertions(+) create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt.sln" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/KMP.c" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/KMP.h" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt.vcxproj" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt.vcxproj.filters" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Main.c" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.c" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.h" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadString.c" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadString.h" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Test.txt" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.c" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.h" create mode 100644 "Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Text.txt" diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt.sln" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt.sln" new file mode 100644 index 0000000..07b4ccd --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt.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}") = "Knuth–Morris–Pratt", "Knuth–Morris–Pratt\Knuth–Morris–Pratt.vcxproj", "{5C13E66F-7004-4B91-82CA-D62CAB4C2071}" +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 + {5C13E66F-7004-4B91-82CA-D62CAB4C2071}.Debug|x64.ActiveCfg = Debug|x64 + {5C13E66F-7004-4B91-82CA-D62CAB4C2071}.Debug|x64.Build.0 = Debug|x64 + {5C13E66F-7004-4B91-82CA-D62CAB4C2071}.Debug|x86.ActiveCfg = Debug|Win32 + {5C13E66F-7004-4B91-82CA-D62CAB4C2071}.Debug|x86.Build.0 = Debug|Win32 + {5C13E66F-7004-4B91-82CA-D62CAB4C2071}.Release|x64.ActiveCfg = Release|x64 + {5C13E66F-7004-4B91-82CA-D62CAB4C2071}.Release|x64.Build.0 = Release|x64 + {5C13E66F-7004-4B91-82CA-D62CAB4C2071}.Release|x86.ActiveCfg = Release|Win32 + {5C13E66F-7004-4B91-82CA-D62CAB4C2071}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F66AE844-2478-4972-BBC9-7D9AFC17B3F7} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/KMP.c" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/KMP.c" new file mode 100644 index 0000000..e072af0 --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/KMP.c" @@ -0,0 +1,66 @@ +#include "KMP.h" +#include +#include + +int* findPrefix(char* substring, int* error) +{ + int* prefix = calloc(strlen(substring) + 1, sizeof(int)); + if (prefix == NULL) + { + *error = 1; + return NULL; + } + prefix[0] = 0; + int i = 1; + int j = 0; + while (substring[i] != '\0') + { + if (substring[j] == substring[i]) + { + prefix[i] = j + 1; + i++; + j++; + } + else if (j == 0) + { + prefix[i] = 0; + i++; + } + else + { + j = prefix[j - 1]; + } + } + return prefix; +} + +int algorithmKMP(char* string, char* substring, int* prefix) +{ + int counterForString = 0; + int CounterForSubstring = 0; + while (string[counterForString] != '\0') + { + if (string[counterForString] == substring[CounterForSubstring]) + { + counterForString++; + CounterForSubstring++; + if (CounterForSubstring == strlen(substring)) + { + return counterForString - strlen(substring) + 1; + } + } + else if (CounterForSubstring == 0) + { + counterForString++; + if (counterForString == strlen(string)) + { + return -1; + } + } + else + { + CounterForSubstring = prefix[CounterForSubstring - 1]; + } + } + return -1; +} \ No newline at end of file diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/KMP.h" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/KMP.h" new file mode 100644 index 0000000..7e582cb --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/KMP.h" @@ -0,0 +1,7 @@ +#pragma once + +// Function for finding the maximum matching suffix and prefix +int* findPrefix(char* substring, int* error); + +// Function for searching for a substring in a string +int algorithmKMP(char* string, char* substring, int* prefix); \ No newline at end of file diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt.vcxproj" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt.vcxproj" new file mode 100644 index 0000000..c149091 --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt.vcxproj" @@ -0,0 +1,157 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {5c13e66f-7004-4b91-82ca-d62cab4c2071} + KnuthMorrisPratt + 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\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt.vcxproj.filters" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt.vcxproj.filters" new file mode 100644 index 0000000..83ddec1 --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt.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/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Main.c" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Main.c" new file mode 100644 index 0000000..ff87934 --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Main.c" @@ -0,0 +1,49 @@ +#include +#include "KMP.h" +#include "ReadString.h" +#include "ReadFile.h" +#include +#include "TestKMP.h" + +int main() +{ + if (!testKMP()) + { + printf("Test failed"); + return -1; + } + printf("enter the substring\n"); + int error = 0; + char* substring = readString(&error); + if (error == 1) + { + printf("memory not allocated"); + return -1; + } + char* string = readFile("Text.txt", &error); + if (error == 1) + { + free(substring); + printf("memory not allocated"); + return -1; + } + if (error == 2) + { + free(substring); + printf("file not found"); + return -1; + } + int* prefix = findPrefix(substring, &error); + if (error == 1) + { + free(string); + free(substring); + printf("memory not allocated"); + return -1; + } + const int result = algorithmKMP(string, substring, prefix); + free(substring); + free(string); + free(prefix); + printf("the position of the first occurrence of the substring in the string (-1 if there is no occurrence) = %d", result); +} \ No newline at end of file diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.c" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.c" new file mode 100644 index 0000000..f7a2d2a --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.c" @@ -0,0 +1,40 @@ +#include +#include + +char* readFile(const char* filename, int* error) +{ + FILE* file = fopen(filename, "r"); + if (file == NULL) + { + *error = 2; + return NULL; + } + int counter = 0; + char temporary = '\0'; + while (!feof(file)) + { + if (fscanf(file, "%c", &temporary) != EOF) + { + counter++; + } + } + fseek(file, 0L, SEEK_SET); + char* string = calloc(counter + 1, sizeof(char)); + if (string == NULL) + { + *error = 1; + return NULL; + } + int newCounter = 0; + while (!feof(file) && newCounter < counter) + { + if (fscanf(file, "%c", &temporary) != EOF) + { + string[newCounter] = temporary; + newCounter++; + } + } + string[newCounter] = '\0'; + fclose(file); + return string; +} \ No newline at end of file diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.h" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.h" new file mode 100644 index 0000000..21de1c0 --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.h" @@ -0,0 +1,4 @@ +#pragma once + +// Function for reading text from a file +char* readFile(const char* filename, int* error); diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadString.c" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadString.c" new file mode 100644 index 0000000..3d219ce --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadString.c" @@ -0,0 +1,36 @@ +#include +#include +#include + +char* readString(int* error) +{ + int index = 0; + int size = 100; + char* array = calloc(size, sizeof(char)); + if (array == NULL) + { + *error = 1; + return NULL; + } + char symbol = getchar(); + while (symbol != '\n') + { + array[index] = symbol; + if (strlen(array) == size) + { + size = size * 2; + char* temporary = realloc(array, size * sizeof(char)); + if (temporary == NULL) + { + *error = 1; + free(array); + return NULL; + } + array = temporary; + } + symbol = getchar(); + index++; + } + array[index] = '\0'; + return array; +} \ No newline at end of file diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadString.h" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadString.h" new file mode 100644 index 0000000..7fc7010 --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadString.h" @@ -0,0 +1,4 @@ +#pragma once + +// Function for entering and reading substrings of arbitrary size +char* readString(int* error); \ No newline at end of file diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Test.txt" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Test.txt" new file mode 100644 index 0000000..8de08e1 --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Test.txt" @@ -0,0 +1 @@ +asdasda sdcdvdsvr rgrggg njn rtr plerg romrovrmvmrov vvjei3-133 wef32f934f eqf0jewjew ascnucbnew8fvh348hvwe wvewrvw wivew0ivew viv eqrgj39q93f34 f3f 3fy834fy348fh3 f34fu 348f34j8f34f8herv834fhvnv ervherver7vhervbryvhrevhhqe7v 134yg834hg3498gy3h4g834gh34g rvjovwevnerubernver vervnrghbftn rfre tkf sdnvjrg7eruvberuvnwer9gfr hfnrjgughnerugberng erguberngijeruveqnvuerhvuervnjv vhreuvhreuvqjwjgioeqr \ No newline at end of file diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.c" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.c" new file mode 100644 index 0000000..aceb262 --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.c" @@ -0,0 +1,44 @@ +#include "TestKMP.h" +#include "ReadFile.h" +#include "KMP.h" +#include "String.h" +#include + +bool testKMP() +{ + int error = 0; + char* string = readFile("Test.txt", &error); + if (error != 0) + { + return false; + } + int* firstPrefix = findPrefix("dcdv", &error); + if (error == 1) + { + free(string); + return false; + } + int* secondPrefix = findPrefix("rfre", &error); + if (error == 1) + { + free(firstPrefix); + free(string); + return false; + } + int* thirdPrefix = findPrefix("eewgeg", &error); + if (error == 1) + { + free(secondPrefix); + free(firstPrefix); + free(string); + return false; + } + const int firstResult = algorithmKMP(string, "dcdv", firstPrefix); + const int secondResult = algorithmKMP(string, "rfre", secondPrefix); + const int thirdResult = algorithmKMP(string, "eewgeg", thirdPrefix); + free(thirdPrefix); + free(secondPrefix); + free(firstPrefix); + free(string); + return firstResult == 10 && secondResult == 289 && thirdResult == -1; +} \ No newline at end of file diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.h" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.h" new file mode 100644 index 0000000..6ce03bf --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.h" @@ -0,0 +1,5 @@ +#pragma once +#include + +// Function for testing the KMP algorithm +bool testKMP(); \ No newline at end of file diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Text.txt" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Text.txt" new file mode 100644 index 0000000..af9e874 --- /dev/null +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Text.txt" @@ -0,0 +1 @@ +acccdercjc ovmv3omvrjrvjrverjvtyu wgbfdbbbbb \ No newline at end of file From 5b0c1f528815227d3ef244257a13d73efaef1bbf Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 12 Dec 2021 22:43:44 +0300 Subject: [PATCH 11/12] fixed bugs --- .../SinglyLinkedListForHashTable.sln | 31 --- .../SinglyLinkedListForHashTable/Main.c | 9 - .../SinglyLinkedListForHashTable.c | 252 ------------------ .../SinglyLinkedListForHashTable.h | 65 ----- .../SinglyLinkedListForHashTable.vcxproj | 153 ----------- ...nglyLinkedListForHashTable.vcxproj.filters | 36 --- .../TestSinglyLinkedListForHashTable.c | 86 ------ .../TestSinglyLinkedListForHashTable.h | 5 - 8 files changed, 637 deletions(-) delete mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.sln delete mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/Main.c delete mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c delete mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h delete mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj delete mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj.filters delete mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c delete mode 100644 SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.sln b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.sln deleted file mode 100644 index d81aa68..0000000 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.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}") = "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 deleted file mode 100644 index 3be54fc..0000000 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/Main.c +++ /dev/null @@ -1,9 +0,0 @@ -#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 deleted file mode 100644 index 1e73ecd..0000000 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c +++ /dev/null @@ -1,252 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#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; -} 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); -} - -bool isOneElement(List* list) -{ - return list->head->next == NULL; -} - -void removeFirstElement(List* list, Error* error) -{ - if (*error != NOT_ERROR) - { - return; - } - if (list->head == NULL) - { - *error = EMPTY_LIST; - return; - } - if (isOneElement(list) && list->head->numberOfDuplicateValues == 1) - { - list->size = 0; - free(list->head->value); - free(list->head); - list->head = NULL; - return; - } - ListElement* element = list->head; - if (element->numberOfDuplicateValues > 1) - { - element->numberOfDuplicateValues--; - return; - } - 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* next(Position* position) -{ - position->position = position->position->next; - return position; -} - -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->head->numberOfDuplicateValues = 1; - return; - } - ListElement* element = list->head; - while (element != NULL) - { - if (strcmp(value, element->value) == 0) - { - element->numberOfDuplicateValues++; - *error = ELEMENT_REPEATS; - return; - } - element = element->next; - } - if (element == 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; - newElement->next = list->head; - list->head = newElement; - list->size++; - newElement->numberOfDuplicateValues = 1; - } -} - -char* getValue(Position* position) -{ - return position->position->value; -} - -bool isEmpty(List* list) -{ - return list->head == 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; -} - -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 deleted file mode 100644 index 486e9ee..0000000 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h +++ /dev/null @@ -1,65 +0,0 @@ -#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); - -// 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 diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj deleted file mode 100644 index d500241..0000000 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj +++ /dev/null @@ -1,153 +0,0 @@ - - - - - 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 deleted file mode 100644 index 950f937..0000000 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.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/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c deleted file mode 100644 index d6d550c..0000000 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c +++ /dev/null @@ -1,86 +0,0 @@ -#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); - const char* firstValue = getHeadValue(newList); - add(newList, "list", &error); - const char* secondValue = getHeadValue(newList); - bool result = strcmp(firstValue, "test") == 0 && strcmp(secondValue, "list") == 0; - 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, "Hello") == 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, "World") == 0 && strcmp(secondValue, "Hello") == 0; - deleteList(newList); - deletePosition(position); - return result; -} - -bool allTest() -{ - return testAdd() && testRemoveHead() && testNumberOfElements() && testGetValue(); -} \ No newline at end of file diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h deleted file mode 100644 index 737bfba..0000000 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once -#include - -// A function that combines the results of all tests -bool allTest(); \ No newline at end of file From dfa9ddbe266acee59a170da465a76fbd254fbfc8 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 12 Dec 2021 22:53:14 +0300 Subject: [PATCH 12/12] removed unnecessary libraries --- .../Knuth\342\200\223Morris\342\200\223Pratt/Main.c" | 2 +- .../Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.c" | 1 + .../Knuth\342\200\223Morris\342\200\223Pratt/ReadString.c" | 1 + .../Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.c" | 1 - 4 files changed, 3 insertions(+), 2 deletions(-) diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Main.c" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Main.c" index ff87934..fe13fc7 100644 --- "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Main.c" +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/Main.c" @@ -1,8 +1,8 @@ -#include #include "KMP.h" #include "ReadString.h" #include "ReadFile.h" #include +#include #include "TestKMP.h" int main() diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.c" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.c" index f7a2d2a..6ce5e66 100644 --- "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.c" +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadFile.c" @@ -1,3 +1,4 @@ +#include "ReadFile.h" #include #include diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadString.c" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadString.c" index 3d219ce..1c3e0c9 100644 --- "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadString.c" +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/ReadString.c" @@ -1,3 +1,4 @@ +#include "ReadString.h" #include #include #include diff --git "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.c" "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.c" index aceb262..9ba2c14 100644 --- "a/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.c" +++ "b/Homework \342\204\22611/Knuth\342\200\223Morris\342\200\223Pratt/Knuth\342\200\223Morris\342\200\223Pratt/TestKMP.c" @@ -1,7 +1,6 @@ #include "TestKMP.h" #include "ReadFile.h" #include "KMP.h" -#include "String.h" #include bool testKMP()