From fa4fefe2b5b7b7449fb66e89908ab09399fca304 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 16:11:40 +0300 Subject: [PATCH 01/17] a list has been written to implement a hash table --- .../SinglyLinkedListForHashTable.sln | 31 +++ .../SinglyLinkedListForHashTable/Main.c | 9 + .../SinglyLinkedListForHashTable.c | 237 ++++++++++++++++++ .../SinglyLinkedListForHashTable.h | 58 +++++ .../SinglyLinkedListForHashTable.vcxproj | 153 +++++++++++ ...nglyLinkedListForHashTable.vcxproj.filters | 36 +++ .../TestSinglyLinkedListForHashTable.c | 100 ++++++++ .../TestSinglyLinkedListForHashTable.h | 5 + 8 files changed, 629 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..595677e --- /dev/null +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c @@ -0,0 +1,237 @@ +#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() +{ + return calloc(1, sizeof(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; + int counter = 0; + for (counter = 1; counter < list->size; counter++) + { + if (strcmp(value, head->value) == 0) + { + head->numberOfDuplicateValues++; + return; + } + head = head->next; + } + if (counter == list->size) + { + 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; +} \ No newline at end of file diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h new file mode 100644 index 0000000..0547f84 --- /dev/null +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h @@ -0,0 +1,58 @@ +#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 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..766e22e --- /dev/null +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c @@ -0,0 +1,100 @@ +#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(); + 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(); + add(newList, "Hello", &error); + add(newList, "World", &error); + add(newList, "Hello", &error); + print(newList); + 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() +{ + List* newList = createList(); + Error error = NOT_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() +{ + List* newList = createList(); + Error error = NOT_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 4b98d8b72cc4d1cca5b2778beead7f305161a4aa Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 16:21:10 +0300 Subject: [PATCH 02/17] removed unnecessary code --- .../TestSinglyLinkedListForHashTable.c | 1 - 1 file changed, 1 deletion(-) diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c index 766e22e..a39c2cc 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c @@ -36,7 +36,6 @@ bool testRemoveHead() add(newList, "Hello", &error); add(newList, "World", &error); add(newList, "Hello", &error); - print(newList); removeFirstElement(newList, &error); if (error == EMPTY_LIST || error == INSUFFICIENT_MEMORY) { From f5f3c42756cd2abef7d94f4711cc3a8a7440bed8 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 20:58:10 +0300 Subject: [PATCH 03/17] writing basic functions for working with a hash table --- HashTable/HashTable.sln | 31 ++++ HashTable/HashTable/HashTable.c | 171 ++++++++++++++++++ HashTable/HashTable/HashTable.h | 12 ++ HashTable/HashTable/HashTable.vcxproj | 155 ++++++++++++++++ HashTable/HashTable/HashTable.vcxproj.filters | 42 +++++ HashTable/HashTable/Main.c | 32 ++++ HashTable/HashTable/TestHashTable.c | 0 HashTable/HashTable/TestHashTable.h | 1 + HashTable/HashTable/Text.txt | 1 + 9 files changed, 445 insertions(+) create mode 100644 HashTable/HashTable.sln create mode 100644 HashTable/HashTable/HashTable.c create mode 100644 HashTable/HashTable/HashTable.h create mode 100644 HashTable/HashTable/HashTable.vcxproj create mode 100644 HashTable/HashTable/HashTable.vcxproj.filters create mode 100644 HashTable/HashTable/Main.c create mode 100644 HashTable/HashTable/TestHashTable.c create mode 100644 HashTable/HashTable/TestHashTable.h create mode 100644 HashTable/HashTable/Text.txt diff --git a/HashTable/HashTable.sln b/HashTable/HashTable.sln new file mode 100644 index 0000000..0faf154 --- /dev/null +++ b/HashTable/HashTable.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}") = "HashTable", "HashTable\HashTable.vcxproj", "{7F515015-3F19-4A2A-9F71-2B4E17988297}" +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 + {7F515015-3F19-4A2A-9F71-2B4E17988297}.Debug|x64.ActiveCfg = Debug|x64 + {7F515015-3F19-4A2A-9F71-2B4E17988297}.Debug|x64.Build.0 = Debug|x64 + {7F515015-3F19-4A2A-9F71-2B4E17988297}.Debug|x86.ActiveCfg = Debug|Win32 + {7F515015-3F19-4A2A-9F71-2B4E17988297}.Debug|x86.Build.0 = Debug|Win32 + {7F515015-3F19-4A2A-9F71-2B4E17988297}.Release|x64.ActiveCfg = Release|x64 + {7F515015-3F19-4A2A-9F71-2B4E17988297}.Release|x64.Build.0 = Release|x64 + {7F515015-3F19-4A2A-9F71-2B4E17988297}.Release|x86.ActiveCfg = Release|Win32 + {7F515015-3F19-4A2A-9F71-2B4E17988297}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4E72E434-3C39-4E83-A4CF-8341EC15AAA4} + EndGlobalSection +EndGlobal diff --git a/HashTable/HashTable/HashTable.c b/HashTable/HashTable/HashTable.c new file mode 100644 index 0000000..d00b593 --- /dev/null +++ b/HashTable/HashTable/HashTable.c @@ -0,0 +1,171 @@ +#include "HashTable.h" +#include +#include +#include + +typedef struct HashTable +{ + int numberOfElements; + int numberOfSegment; + struct List** array; +} HashTable; + +HashTable* createTable(Error* error) +{ + if (*error != NOT_ERROR) + { + return NULL; + } + HashTable* table = calloc(1, sizeof(HashTable)); + if (table == NULL) + { + *error = INSUFFICIENT_MEMORY; + return NULL; + } + table->numberOfSegment = 100; + table->array = calloc(100, sizeof(List*)); + if (table->array == NULL) + { + free(table); + *error = INSUFFICIENT_MEMORY; + return NULL; + } + for (int i = 0; i < table->numberOfSegment; i++) + { + table->array[i] = createList(error); + if (*error != NOT_ERROR) + { + break; + } + } + return table; +} + +void deleteHashTable(HashTable* table) +{ + for (int i = 0; i < table->numberOfSegment; i++) + { + deleteList(table->array[i]); + } + free(table->array); + free(table); +} + +int hashFunction(const char* string, HashTable* table) +{ + int result = 0; + for (int i = 0; string[i] != '\0'; i++) + { + result = (result + string[i]) % table->numberOfSegment; + } + return result; +} + +HashTable* resize(HashTable* table, Error* error) +{ + if (*error != NOT_ERROR) + { + return table; + } + HashTable* newTable = calloc(1, sizeof(HashTable)); + if (newTable == NULL) + { + *error = INSUFFICIENT_MEMORY; + return table; + } + newTable->array = calloc(table->numberOfSegment * 2, sizeof(List*)); + if (newTable->array == NULL) + { + free(newTable); + *error = INSUFFICIENT_MEMORY; + return table; + } + newTable->numberOfSegment = table->numberOfSegment * 2; + for (int i = 0; i < table->numberOfSegment * 2; i++) + { + newTable->array[i] = createList(error); + if (*error != NOT_ERROR) + { + break; + } + } + for (int i = 0; i < table->numberOfSegment; i++) + { + while (!isEmpty(table->array[i])) + { + char* newString = calloc(strlen(getHeadValue(table->array[i])) + 1, sizeof(char)); + if (newString == NULL) + { + for (int i = 0; i < table->numberOfSegment * 2; i++) + { + free(newTable->array[i]); + } + free(newTable->array); + free(newTable); + return table; + } + strcpy(newString, getHeadValue(table->array[i])); + add(newTable->array[i], newString, error); + removeFirstElement(table->array[i], error); + } + deleteList(table->array[i]); + } + newTable->numberOfElements = table->numberOfElements; + free(table->array); + free(table); + return newTable; +} + +void addElement(const char* string, HashTable* table, Error* error) +{ + if (*error != NOT_ERROR) + { + return; + } + float factor = (float)(table->numberOfElements) / (float)(table->numberOfSegment); + if (factor > 1.5) + { + table = resize(table, error); + } + add(table->array[hashFunction(string, table)], string, error); + if (*error == INSUFFICIENT_MEMORY) + { + return; + } + if (*error != ELEMENT_REPEATS) + { + table->numberOfElements++; + return; + } + error = NOT_ERROR; +} + +void printValue(HashTable* table) +{ + int maximumListLength = numberOfElements(table->array[0]); + int numberOfompletedBuckets = 0; + int totalSizeOfAllLists = 0; + for (int i = 0; i < table->numberOfSegment; i++) + { + print(table->array[i]); + if (!isEmpty(table->array[i])) + { + numberOfompletedBuckets++; + } + int listLength = numberOfElements(table->array[i]); + totalSizeOfAllLists += listLength; + if (listLength > maximumListLength) + { + maximumListLength = listLength; + } + } + printf("maximum list lenght = %d\n", maximumListLength); + printf("hash table fill factor = %f\n", (float)(table->numberOfElements) / (float)(table->numberOfSegment)); + printf("average list length = %f\n", (float)(totalSizeOfAllLists) / (float)(numberOfompletedBuckets)); +} + +void findElement(HashTable* table, char* string) +{ + int hash = hashFunction(string, table); + +} \ No newline at end of file diff --git a/HashTable/HashTable/HashTable.h b/HashTable/HashTable/HashTable.h new file mode 100644 index 0000000..da14c7d --- /dev/null +++ b/HashTable/HashTable/HashTable.h @@ -0,0 +1,12 @@ +#pragma once +#include "../../SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" + +typedef struct HashTable HashTable; + +HashTable* createTable(Error* error); + +void deleteHashTable(HashTable* table); + +void addElement(const char* string, HashTable* table, Error* error); + +void printValue(HashTable* table); \ No newline at end of file diff --git a/HashTable/HashTable/HashTable.vcxproj b/HashTable/HashTable/HashTable.vcxproj new file mode 100644 index 0000000..b947f3c --- /dev/null +++ b/HashTable/HashTable/HashTable.vcxproj @@ -0,0 +1,155 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {7f515015-3f19-4a2a-9f71-2b4e17988297} + HashTable + 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/HashTable/HashTable/HashTable.vcxproj.filters b/HashTable/HashTable/HashTable.vcxproj.filters new file mode 100644 index 0000000..6732d01 --- /dev/null +++ b/HashTable/HashTable/HashTable.vcxproj.filters @@ -0,0 +1,42 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + + + Файлы заголовков + + + Файлы заголовков + + + Файлы заголовков + + + \ No newline at end of file diff --git a/HashTable/HashTable/Main.c b/HashTable/HashTable/Main.c new file mode 100644 index 0000000..20315db --- /dev/null +++ b/HashTable/HashTable/Main.c @@ -0,0 +1,32 @@ +#include +#include "HashTable.h" + +int readPhonebook(HashTable* table, const char* fileName) +{ + FILE* file = fopen(fileName, "r"); + if (file == NULL) + { + return -1; + } + while (!feof(file)) + { + // words in the file are less than 100 characters in size + char array[100] = { '\0' }; + Error error = NOT_ERROR; + if (fscanf(file, "%s", array) != EOF); + { + addElement(array, table, &error); + } + } + fclose(file); + return 0; +} + +int main() +{ + Error error = NOT_ERROR; + HashTable* table = createTable(&error); + readPhonebook(table, "Text.txt"); + printValue(table); + deleteHashTable(table); +} \ No newline at end of file diff --git a/HashTable/HashTable/TestHashTable.c b/HashTable/HashTable/TestHashTable.c new file mode 100644 index 0000000..e69de29 diff --git a/HashTable/HashTable/TestHashTable.h b/HashTable/HashTable/TestHashTable.h new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/HashTable/HashTable/TestHashTable.h @@ -0,0 +1 @@ +#pragma once diff --git a/HashTable/HashTable/Text.txt b/HashTable/HashTable/Text.txt new file mode 100644 index 0000000..3f4342d --- /dev/null +++ b/HashTable/HashTable/Text.txt @@ -0,0 +1 @@ +Hello world Hello Kekekek Hello \ No newline at end of file From 823c97ca541a8a637305666f653f6b211ec32526 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 21:13:20 +0300 Subject: [PATCH 04/17] writing basic functions for working with a hash table --- .../SinglyLinkedListForHashTable.c | 29 +++++++++++++++---- .../SinglyLinkedListForHashTable.h | 10 +++++-- .../TestSinglyLinkedListForHashTable.c | 13 ++++----- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c index 595677e..fd6d1cf 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c @@ -26,9 +26,14 @@ typedef struct Position ListElement* position; } Position; -List* createList() +List* createList(Error* error) { - return calloc(1, sizeof(List)); + List* list = calloc(1, sizeof(List)); + if (list == NULL) + { + *error = INSUFFICIENT_MEMORY; + } + return list; } void deleteList(List* list) @@ -164,17 +169,17 @@ void add(List* list, const char* value, Error* error) return; } ListElement* head = list->head; - int counter = 0; - for (counter = 1; counter < list->size; counter++) + while (head != NULL) { if (strcmp(value, head->value) == 0) { head->numberOfDuplicateValues++; + *error = ELEMENT_REPEATS; return; } head = head->next; } - if (counter == list->size) + if (head == NULL) { char* valueCopy = calloc(strlen(value) + 1, sizeof(char)); if (valueCopy == NULL) @@ -234,4 +239,18 @@ const char* decodingError(Error error) 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 index 0547f84..c3a2029 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h @@ -12,11 +12,12 @@ typedef enum Error { NOT_ERROR, EMPTY_LIST, - INSUFFICIENT_MEMORY + INSUFFICIENT_MEMORY, + ELEMENT_REPEATS } Error; // Function for creating a list -List* createList(); +List* createList(Error* error); // Function for deleting a list void deleteList(List* list); @@ -55,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 for determining the location of an item in the list +bool inList(List* list, const char* value); \ No newline at end of file diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c index a39c2cc..25bcb12 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c @@ -6,7 +6,7 @@ bool testAdd() { Error error = NOT_ERROR; - List* newList = createList(); + List* newList = createList(&error); add(newList, "test", &error); add(newList, "list", &error); if (error == INSUFFICIENT_MEMORY) @@ -32,10 +32,9 @@ bool testAdd() bool testRemoveHead() { Error error = NOT_ERROR; - List* newList = createList(); + List* newList = createList(&error); add(newList, "Hello", &error); add(newList, "World", &error); - add(newList, "Hello", &error); removeFirstElement(newList, &error); if (error == EMPTY_LIST || error == INSUFFICIENT_MEMORY) { @@ -51,12 +50,12 @@ bool testRemoveHead() // Function for checking the function counting the number of elements bool testNumberOfElements() { - List* newList = createList(); Error error = NOT_ERROR; + 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); @@ -70,8 +69,8 @@ bool testNumberOfElements() // Function that checks the function that returns the value of the first element bool testGetValue() { - List* newList = createList(); Error error = NOT_ERROR; + List* newList = createList(&error); add(newList, "Hello", &error); add(newList, "World", &error); if (error == INSUFFICIENT_MEMORY) From c2ecc547703c636cf96a49b9c3d5dec599919ae4 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 21:40:26 +0300 Subject: [PATCH 05/17] the basic functions for working with a hash table are written --- HashTable/HashTable/HashTable.c | 5 ++--- HashTable/HashTable/HashTable.h | 4 +++- HashTable/HashTable/Main.c | 29 ++++------------------------- HashTable/HashTable/TestHashTable.c | 16 ++++++++++++++++ HashTable/HashTable/TestHashTable.h | 3 +++ 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/HashTable/HashTable/HashTable.c b/HashTable/HashTable/HashTable.c index d00b593..1a37e9b 100644 --- a/HashTable/HashTable/HashTable.c +++ b/HashTable/HashTable/HashTable.c @@ -164,8 +164,7 @@ void printValue(HashTable* table) printf("average list length = %f\n", (float)(totalSizeOfAllLists) / (float)(numberOfompletedBuckets)); } -void findElement(HashTable* table, char* string) +bool inTable(HashTable* table, char* string) { - int hash = hashFunction(string, table); - + return inList(table->array[hashFunction(string, table)], string); } \ No newline at end of file diff --git a/HashTable/HashTable/HashTable.h b/HashTable/HashTable/HashTable.h index da14c7d..b930b8a 100644 --- a/HashTable/HashTable/HashTable.h +++ b/HashTable/HashTable/HashTable.h @@ -9,4 +9,6 @@ void deleteHashTable(HashTable* table); void addElement(const char* string, HashTable* table, Error* error); -void printValue(HashTable* table); \ No newline at end of file +void printValue(HashTable* table); + +bool inTable(HashTable* table, char* string); \ No newline at end of file diff --git a/HashTable/HashTable/Main.c b/HashTable/HashTable/Main.c index 20315db..fec8f6a 100644 --- a/HashTable/HashTable/Main.c +++ b/HashTable/HashTable/Main.c @@ -1,32 +1,11 @@ -#include +#include "TestHashTable.h" #include "HashTable.h" +#include -int readPhonebook(HashTable* table, const char* fileName) +int main() { - FILE* file = fopen(fileName, "r"); - if (file == NULL) + if (!testAddElement()) { return -1; } - while (!feof(file)) - { - // words in the file are less than 100 characters in size - char array[100] = { '\0' }; - Error error = NOT_ERROR; - if (fscanf(file, "%s", array) != EOF); - { - addElement(array, table, &error); - } - } - fclose(file); - return 0; -} - -int main() -{ - Error error = NOT_ERROR; - HashTable* table = createTable(&error); - readPhonebook(table, "Text.txt"); - printValue(table); - deleteHashTable(table); } \ No newline at end of file diff --git a/HashTable/HashTable/TestHashTable.c b/HashTable/HashTable/TestHashTable.c index e69de29..b7fbdc7 100644 --- a/HashTable/HashTable/TestHashTable.c +++ b/HashTable/HashTable/TestHashTable.c @@ -0,0 +1,16 @@ +#include "TestHashTable.h" +#include "HashTable.h" + +bool testAddElement() +{ + Error error = NOT_ERROR; + HashTable* table = createTable(&error); + addElement("Hello", table, &error); + addElement("World", table, &error); + addElement("Test", table, &error); + bool firstResult = inTable(table, "Hello"); + bool secondResult = inTable(table, "World"); + bool thirdResult = inTable(table, "Test"); + deleteHashTable(table); + return firstResult && secondResult && thirdResult; +} \ No newline at end of file diff --git a/HashTable/HashTable/TestHashTable.h b/HashTable/HashTable/TestHashTable.h index 6f70f09..44d837e 100644 --- a/HashTable/HashTable/TestHashTable.h +++ b/HashTable/HashTable/TestHashTable.h @@ -1 +1,4 @@ #pragma once +#include + +bool testAddElement(); From 03c083fc0ec026583c23a0e4f5e23b757234d2a7 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 22:47:35 +0300 Subject: [PATCH 06/17] work has been done with the file --- HashTable/HashTable/Text.txt | 1 - .../FrequencyOfOccurrenceOfWords.sln" | 31 ++++ .../FrequencyOfOccurrenceOfWords.c" | 21 +++ .../FrequencyOfOccurrenceOfWords.vcxproj" | 157 ++++++++++++++++++ ...quencyOfOccurrenceOfWords.vcxproj.filters" | 16 +- .../FrequencyOfOccurrenceOfWords/ReadFile.c" | 28 ++++ .../FrequencyOfOccurrenceOfWords/ReadFile.h" | 4 + .../TestReadFileUsingHashTable.c" | 18 ++ .../TestReadFileUsingHashTable.h" | 4 + .../FrequencyOfOccurrenceOfWords/Text.txt" | 29 ++++ .../HashTable/HashTable.sln" | 0 .../HashTable/HashTable/HashTable.c" | 0 .../HashTable/HashTable/HashTable.h" | 0 .../HashTable/HashTable/HashTable.vcxproj" | 0 .../HashTable/HashTable/Main.c" | 0 .../HashTable/HashTable/TestHashTable.c" | 0 .../HashTable/HashTable/TestHashTable.h" | 0 .../SinglyLinkedListForHashTable.sln" | 0 .../SinglyLinkedListForHashTable/Main.c" | 0 .../SinglyLinkedListForHashTable.c" | 0 .../SinglyLinkedListForHashTable.h" | 0 .../SinglyLinkedListForHashTable.vcxproj" | 0 ...glyLinkedListForHashTable.vcxproj.filters" | 0 .../TestSinglyLinkedListForHashTable.c" | 0 .../TestSinglyLinkedListForHashTable.h" | 0 25 files changed, 303 insertions(+), 6 deletions(-) delete mode 100644 HashTable/HashTable/Text.txt create mode 100644 "Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.sln" create mode 100644 "Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" create mode 100644 "Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.vcxproj" rename HashTable/HashTable/HashTable.vcxproj.filters => "Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.vcxproj.filters" (76%) create mode 100644 "Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" create mode 100644 "Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.h" create mode 100644 "Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" create mode 100644 "Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.h" create mode 100644 "Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/Text.txt" rename HashTable/HashTable.sln => "Homework \342\204\226 9/HashTable/HashTable.sln" (100%) rename HashTable/HashTable/HashTable.c => "Homework \342\204\226 9/HashTable/HashTable/HashTable.c" (100%) rename HashTable/HashTable/HashTable.h => "Homework \342\204\226 9/HashTable/HashTable/HashTable.h" (100%) rename HashTable/HashTable/HashTable.vcxproj => "Homework \342\204\226 9/HashTable/HashTable/HashTable.vcxproj" (100%) rename HashTable/HashTable/Main.c => "Homework \342\204\226 9/HashTable/HashTable/Main.c" (100%) rename HashTable/HashTable/TestHashTable.c => "Homework \342\204\226 9/HashTable/HashTable/TestHashTable.c" (100%) rename HashTable/HashTable/TestHashTable.h => "Homework \342\204\226 9/HashTable/HashTable/TestHashTable.h" (100%) rename SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.sln => "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.sln" (100%) rename SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/Main.c => "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/Main.c" (100%) rename SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c => "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c" (100%) rename SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h => "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" (100%) rename SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj => "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj" (100%) rename SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj.filters => "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj.filters" (100%) rename SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c => "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c" (100%) rename SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h => "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h" (100%) diff --git a/HashTable/HashTable/Text.txt b/HashTable/HashTable/Text.txt deleted file mode 100644 index 3f4342d..0000000 --- a/HashTable/HashTable/Text.txt +++ /dev/null @@ -1 +0,0 @@ -Hello world Hello Kekekek Hello \ No newline at end of file diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.sln" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.sln" new file mode 100644 index 0000000..003894e --- /dev/null +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.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}") = "FrequencyOfOccurrenceOfWords", "FrequencyOfOccurrenceOfWords\FrequencyOfOccurrenceOfWords.vcxproj", "{ECBF2784-C770-44C8-A208-31046468F94E}" +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 + {ECBF2784-C770-44C8-A208-31046468F94E}.Debug|x64.ActiveCfg = Debug|x64 + {ECBF2784-C770-44C8-A208-31046468F94E}.Debug|x64.Build.0 = Debug|x64 + {ECBF2784-C770-44C8-A208-31046468F94E}.Debug|x86.ActiveCfg = Debug|Win32 + {ECBF2784-C770-44C8-A208-31046468F94E}.Debug|x86.Build.0 = Debug|Win32 + {ECBF2784-C770-44C8-A208-31046468F94E}.Release|x64.ActiveCfg = Release|x64 + {ECBF2784-C770-44C8-A208-31046468F94E}.Release|x64.Build.0 = Release|x64 + {ECBF2784-C770-44C8-A208-31046468F94E}.Release|x86.ActiveCfg = Release|Win32 + {ECBF2784-C770-44C8-A208-31046468F94E}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DD9F0B46-CB0B-4502-8346-C982FBFEB6C1} + EndGlobalSection +EndGlobal diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" new file mode 100644 index 0000000..d16cada --- /dev/null +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" @@ -0,0 +1,21 @@ +#include "ReadFile.h" +#include + +int main() +{ + Error error = NOT_ERROR; + HashTable* table = createTable(&error); + int result = readFile(table, "Text.txt"); + if (result == -1) + { + printf("File not found"); + return -1; + } + if (error == INSUFFICIENT_MEMORY) + { + printf("Memory not allocated"); + return -1; + } + printValue(table); + deleteHashTable(table); +} \ No newline at end of file diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.vcxproj" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.vcxproj" new file mode 100644 index 0000000..d4c299f --- /dev/null +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.vcxproj" @@ -0,0 +1,157 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {ecbf2784-c770-44c8-a208-31046468f94e} + FrequencyOfOccurrenceOfWords + 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 + true + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + 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/HashTable/HashTable/HashTable.vcxproj.filters "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.vcxproj.filters" similarity index 76% rename from HashTable/HashTable/HashTable.vcxproj.filters rename to "Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.vcxproj.filters" index 6732d01..5f60d17 100644 --- a/HashTable/HashTable/HashTable.vcxproj.filters +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.vcxproj.filters" @@ -15,27 +15,33 @@ - + + Исходные файлы + + Исходные файлы Исходные файлы - + Исходные файлы - + Исходные файлы + + Файлы заголовков + Файлы заголовков - + Файлы заголовков - + Файлы заголовков diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" new file mode 100644 index 0000000..3cd2664 --- /dev/null +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" @@ -0,0 +1,28 @@ +#include +#include "ReadFile.h" + +int readFile(HashTable* table, const char* fileName) +{ + FILE* file = fopen(fileName, "r"); + if (file == NULL) + { + return -1; + } + while (!feof(file)) + { + // words in the file are less than 100 characters in size + char array[100] = { '\0' }; + Error error = NOT_ERROR; + if (fscanf(file, "%s", array) != EOF); + { + addElement(array, table, &error); + if (error == INSUFFICIENT_MEMORY) + { + deleteHashTable(table); + return -2; + } + } + } + fclose(file); + return 0; +} diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.h" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.h" new file mode 100644 index 0000000..22f9ad1 --- /dev/null +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.h" @@ -0,0 +1,4 @@ +#pragma once +#include "../../HashTable/HashTable/HashTable.h" + +int readFile(HashTable* table, const char* fileName); diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" new file mode 100644 index 0000000..6b3982f --- /dev/null +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" @@ -0,0 +1,18 @@ +#include "TestReadFileUsingHashTable.h" +#include "ReadFile.h" + +bool testReadFileUsingHashTable() +{ + Error error = NOT_ERROR; + HashTable* table = createTable(&error); + int result = readFile(table, "Test.txt"); + if (result == -1) + { + return false; + } + if (error == INSUFFICIENT_MEMORY) + { + return false; + } + deleteHashTable(table); +} \ No newline at end of file diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.h" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.h" new file mode 100644 index 0000000..feebdfd --- /dev/null +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.h" @@ -0,0 +1,4 @@ +#pragma once +#include + +bool testReadFileUsingHashTable(); \ No newline at end of file diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/Text.txt" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/Text.txt" new file mode 100644 index 0000000..fc1aeb9 --- /dev/null +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/Text.txt" @@ -0,0 +1,29 @@ +Night and silence given for ages +Rain or maybe it is snowing +Anyway I am warmed up with an endless hope +I see a city far away which does not exist + +There where it is easy to find a shelter for a stranger +Where for sure they remember you and wait for you +Day by day losing or confusing a trace +I go to this city which does not exist + +There a hearth is burning for me +Like an eternal sign of forgotten truth +There is the last step till it +And this step is longer than the life + +Who will answer me what is given by destiny +Let it be not fated to know about it +Perhaps behind a threshold of the waisted years +I will find this city which does not exist + +There a hearth is burning for me +Like an eternal sign of forgotten truth +There is the last step till it +And this step is longer than the life + +There a hearth is burning for me +Like an eternal sign of forgotten truth +There is the last step till it +And this step is longer than the life \ No newline at end of file diff --git a/HashTable/HashTable.sln "b/Homework \342\204\226 9/HashTable/HashTable.sln" similarity index 100% rename from HashTable/HashTable.sln rename to "Homework \342\204\226 9/HashTable/HashTable.sln" diff --git a/HashTable/HashTable/HashTable.c "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" similarity index 100% rename from HashTable/HashTable/HashTable.c rename to "Homework \342\204\226 9/HashTable/HashTable/HashTable.c" diff --git a/HashTable/HashTable/HashTable.h "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.h" similarity index 100% rename from HashTable/HashTable/HashTable.h rename to "Homework \342\204\226 9/HashTable/HashTable/HashTable.h" diff --git a/HashTable/HashTable/HashTable.vcxproj "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.vcxproj" similarity index 100% rename from HashTable/HashTable/HashTable.vcxproj rename to "Homework \342\204\226 9/HashTable/HashTable/HashTable.vcxproj" diff --git a/HashTable/HashTable/Main.c "b/Homework \342\204\226 9/HashTable/HashTable/Main.c" similarity index 100% rename from HashTable/HashTable/Main.c rename to "Homework \342\204\226 9/HashTable/HashTable/Main.c" diff --git a/HashTable/HashTable/TestHashTable.c "b/Homework \342\204\226 9/HashTable/HashTable/TestHashTable.c" similarity index 100% rename from HashTable/HashTable/TestHashTable.c rename to "Homework \342\204\226 9/HashTable/HashTable/TestHashTable.c" diff --git a/HashTable/HashTable/TestHashTable.h "b/Homework \342\204\226 9/HashTable/HashTable/TestHashTable.h" similarity index 100% rename from HashTable/HashTable/TestHashTable.h rename to "Homework \342\204\226 9/HashTable/HashTable/TestHashTable.h" diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.sln "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.sln" similarity index 100% rename from SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.sln rename to "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.sln" diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/Main.c "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/Main.c" similarity index 100% rename from SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/Main.c rename to "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/Main.c" diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c" similarity index 100% rename from SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c rename to "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c" diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" similarity index 100% rename from SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h rename to "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj" similarity index 100% rename from SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj rename to "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj" diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj.filters "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj.filters" similarity index 100% rename from SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj.filters rename to "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj.filters" diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c" similarity index 100% rename from SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c rename to "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c" diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h" similarity index 100% rename from SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h rename to "Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.h" From 6f63967f448878688f6ea5a699be0e92e6724d00 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 22:55:10 +0300 Subject: [PATCH 07/17] added a function to count the number of duplicate elements --- .../SinglyLinkedListForHashTable.c | 14 ++++++++++++++ .../SinglyLinkedListForHashTable.h | 5 ++++- .../SinglyLinkedListForHashTable.vcxproj | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c index fd6d1cf..358de4a 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c @@ -253,4 +253,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 c3a2029..486e9ee 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h @@ -59,4 +59,7 @@ char* getValue(Position* position); const char* decodingError(Error error); // Function for determining the location of an item in the list -bool inList(List* list, const char* value); \ No newline at end of file +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 index d500241..0fe234a 100644 --- a/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj +++ b/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.vcxproj @@ -114,7 +114,7 @@ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true From dd937c554feca25db24bdf4053a3f19ad6bbf2b7 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 23:08:33 +0300 Subject: [PATCH 08/17] Added comments --- HashTable/HashTable/HashTable.c | 5 +++++ HashTable/HashTable/HashTable.h | 11 ++++++++++- HashTable/HashTable/TestHashTable.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/HashTable/HashTable/HashTable.c b/HashTable/HashTable/HashTable.c index 1a37e9b..9340bbb 100644 --- a/HashTable/HashTable/HashTable.c +++ b/HashTable/HashTable/HashTable.c @@ -167,4 +167,9 @@ void printValue(HashTable* table) bool inTable(HashTable* table, char* string) { return inList(table->array[hashFunction(string, table)], string); +} + +int countNumberOfDuplicateItemsForSpecificList(char* value, HashTable* table) +{ + return returnNumberOfDuplicateValues(table->array[hashFunction(value, table)], value); } \ No newline at end of file diff --git a/HashTable/HashTable/HashTable.h b/HashTable/HashTable/HashTable.h index b930b8a..5421bad 100644 --- a/HashTable/HashTable/HashTable.h +++ b/HashTable/HashTable/HashTable.h @@ -1,14 +1,23 @@ #pragma once #include "../../SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" +// Structure representing a hash table typedef struct HashTable HashTable; +// Function for creating a hash table HashTable* createTable(Error* error); +// Function for deleting a hash table void deleteHashTable(HashTable* table); +// Function for adding an element to a hash table void addElement(const char* string, HashTable* table, Error* error); +// Function for printing values void printValue(HashTable* table); -bool inTable(HashTable* table, char* string); \ No newline at end of file +// Function for checking the location of an element in the table +bool inTable(HashTable* table, char* string); + +// Function for counting the number of duplicate items for a specific list +int countNumberOfDuplicateItemsForSpecificList(char* value, HashTable* table); \ No newline at end of file diff --git a/HashTable/HashTable/TestHashTable.h b/HashTable/HashTable/TestHashTable.h index 44d837e..3951eb9 100644 --- a/HashTable/HashTable/TestHashTable.h +++ b/HashTable/HashTable/TestHashTable.h @@ -1,4 +1,5 @@ #pragma once #include +// Function to check the function to add an element bool testAddElement(); From b8c7f28fab5e31ef29bb4615eadfb0cf6df0bb41 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 23:23:43 +0300 Subject: [PATCH 09/17] Added comments --- .../FrequencyOfOccurrenceOfWords.c" | 7 +++++++ .../FrequencyOfOccurrenceOfWords/ReadFile.c" | 1 - .../FrequencyOfOccurrenceOfWords/ReadFile.h" | 1 + .../FrequencyOfOccurrenceOfWords/Test.txt" | 1 + .../TestReadFileUsingHashTable.c" | 10 ++++++++++ .../TestReadFileUsingHashTable.h" | 1 + 6 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 "Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/Test.txt" diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" index d16cada..dbcc64d 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" @@ -1,18 +1,25 @@ #include "ReadFile.h" +#include "TestReadFileUsingHashTable.h" #include int main() { + if (!testReadFileUsingHashTable()) + { + return -1; + } Error error = NOT_ERROR; HashTable* table = createTable(&error); int result = readFile(table, "Text.txt"); if (result == -1) { + deleteHashTable(table); printf("File not found"); return -1; } if (error == INSUFFICIENT_MEMORY) { + deleteHashTable(table); printf("Memory not allocated"); return -1; } diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" index 3cd2664..30ae2c7 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" @@ -18,7 +18,6 @@ int readFile(HashTable* table, const char* fileName) addElement(array, table, &error); if (error == INSUFFICIENT_MEMORY) { - deleteHashTable(table); return -2; } } diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.h" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.h" index 22f9ad1..8ede5c4 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.h" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.h" @@ -1,4 +1,5 @@ #pragma once #include "../../HashTable/HashTable/HashTable.h" +// Function for reading a file int readFile(HashTable* table, const char* fileName); diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/Test.txt" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/Test.txt" new file mode 100644 index 0000000..295de45 --- /dev/null +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/Test.txt" @@ -0,0 +1 @@ +Hello World S Hello Hello S World Test Commit A S \ No newline at end of file diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" index 6b3982f..067254a 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" @@ -8,11 +8,21 @@ bool testReadFileUsingHashTable() int result = readFile(table, "Test.txt"); if (result == -1) { + deleteHashTable(table); return false; } if (error == INSUFFICIENT_MEMORY) { + deleteHashTable(table); return false; } + const int firstCheck = countNumberOfDuplicateItemsForSpecificList("Hello", table); + const int secondCheck = countNumberOfDuplicateItemsForSpecificList("World", table); + const int thirdCheck = countNumberOfDuplicateItemsForSpecificList("Test", table); + const int fourthCheck = countNumberOfDuplicateItemsForSpecificList("Commit", table); + const int fifthCheck = countNumberOfDuplicateItemsForSpecificList("A", table); + const int sixthCheck = countNumberOfDuplicateItemsForSpecificList("S", table); deleteHashTable(table); + return firstCheck == 3 && secondCheck == 2 && thirdCheck == 1 + && fourthCheck == 1 && fifthCheck == 1 && sixthCheck == 3; } \ No newline at end of file diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.h" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.h" index feebdfd..ffa3433 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.h" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.h" @@ -1,4 +1,5 @@ #pragma once #include +// Function for checking the counting of words in the text bool testReadFileUsingHashTable(); \ No newline at end of file From 8224d00c4cd9fa717acec12b33e4ca7a7e9006dd Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 23:35:14 +0300 Subject: [PATCH 10/17] changed the function to expand the size of the array --- HashTable/HashTable/HashTable.c | 20 +++++++++++--------- HashTable/HashTable/HashTable.vcxproj | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/HashTable/HashTable/HashTable.c b/HashTable/HashTable/HashTable.c index 9340bbb..bb25cfc 100644 --- a/HashTable/HashTable/HashTable.c +++ b/HashTable/HashTable/HashTable.c @@ -73,19 +73,21 @@ HashTable* resize(HashTable* table, Error* error) *error = INSUFFICIENT_MEMORY; return table; } - newTable->array = calloc(table->numberOfSegment * 2, sizeof(List*)); + newTable->numberOfSegment = table->numberOfSegment * 2; + newTable->array = calloc(newTable->numberOfSegment, sizeof(List*)); if (newTable->array == NULL) { free(newTable); *error = INSUFFICIENT_MEMORY; return table; } - newTable->numberOfSegment = table->numberOfSegment * 2; - for (int i = 0; i < table->numberOfSegment * 2; i++) + for (int i = 0; i < newTable->numberOfSegment; i++) { newTable->array[i] = createList(error); if (*error != NOT_ERROR) { + *error = INSUFFICIENT_MEMORY; + deleteHashTable(newTable); break; } } @@ -96,12 +98,8 @@ HashTable* resize(HashTable* table, Error* error) char* newString = calloc(strlen(getHeadValue(table->array[i])) + 1, sizeof(char)); if (newString == NULL) { - for (int i = 0; i < table->numberOfSegment * 2; i++) - { - free(newTable->array[i]); - } - free(newTable->array); - free(newTable); + *error = INSUFFICIENT_MEMORY; + deleteHashTable(newTable); return table; } strcpy(newString, getHeadValue(table->array[i])); @@ -126,6 +124,10 @@ void addElement(const char* string, HashTable* table, Error* error) if (factor > 1.5) { table = resize(table, error); + if (*error != NOT_ERROR) + { + return; + } } add(table->array[hashFunction(string, table)], string, error); if (*error == INSUFFICIENT_MEMORY) diff --git a/HashTable/HashTable/HashTable.vcxproj b/HashTable/HashTable/HashTable.vcxproj index b947f3c..a5aea2f 100644 --- a/HashTable/HashTable/HashTable.vcxproj +++ b/HashTable/HashTable/HashTable.vcxproj @@ -114,7 +114,7 @@ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true From 6e4416dc2884044aa5927205694c1bae9d515cae Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 27 Nov 2021 23:53:05 +0300 Subject: [PATCH 11/17] commit --- .../HashTable/HashTable.vcxproj.filters" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "Homework \342\204\226 9/HashTable/HashTable/HashTable.vcxproj.filters" diff --git "a/Homework \342\204\226 9/HashTable/HashTable/HashTable.vcxproj.filters" "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.vcxproj.filters" new file mode 100644 index 0000000..6732d01 --- /dev/null +++ "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.vcxproj.filters" @@ -0,0 +1,42 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + + + Файлы заголовков + + + Файлы заголовков + + + Файлы заголовков + + + \ No newline at end of file From bb3dc4ddae3717405d0837e4fb31cf66f665a653 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Wed, 1 Dec 2021 00:28:47 +0300 Subject: [PATCH 12/17] trying to write a function to add an element --- .../FrequencyOfOccurrenceOfWords.c" | 2 +- .../FrequencyOfOccurrenceOfWords/ReadFile.c" | 2 +- .../FrequencyOfOccurrenceOfWords/ReadFile.h" | 2 +- .../TestReadFileUsingHashTable.c" | 2 +- .../FrequencyOfOccurrenceOfWords/Text.txt" | 30 +------------------ 5 files changed, 5 insertions(+), 33 deletions(-) diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" index dbcc64d..f9a27bd 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" @@ -10,7 +10,7 @@ int main() } Error error = NOT_ERROR; HashTable* table = createTable(&error); - int result = readFile(table, "Text.txt"); + int result = readFile(&table, "Text.txt"); if (result == -1) { deleteHashTable(table); diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" index 30ae2c7..c449751 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" @@ -1,7 +1,7 @@ #include #include "ReadFile.h" -int readFile(HashTable* table, const char* fileName) +int readFile(HashTable** table, const char* fileName) { FILE* file = fopen(fileName, "r"); if (file == NULL) diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.h" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.h" index 8ede5c4..0864cbd 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.h" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.h" @@ -2,4 +2,4 @@ #include "../../HashTable/HashTable/HashTable.h" // Function for reading a file -int readFile(HashTable* table, const char* fileName); +int readFile(HashTable** table, const char* fileName); diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" index 067254a..c6c273f 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" @@ -5,7 +5,7 @@ bool testReadFileUsingHashTable() { Error error = NOT_ERROR; HashTable* table = createTable(&error); - int result = readFile(table, "Test.txt"); + int result = readFile(&table, "Test.txt"); if (result == -1) { deleteHashTable(table); diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/Text.txt" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/Text.txt" index fc1aeb9..7358f51 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/Text.txt" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/Text.txt" @@ -1,29 +1 @@ -Night and silence given for ages -Rain or maybe it is snowing -Anyway I am warmed up with an endless hope -I see a city far away which does not exist - -There where it is easy to find a shelter for a stranger -Where for sure they remember you and wait for you -Day by day losing or confusing a trace -I go to this city which does not exist - -There a hearth is burning for me -Like an eternal sign of forgotten truth -There is the last step till it -And this step is longer than the life - -Who will answer me what is given by destiny -Let it be not fated to know about it -Perhaps behind a threshold of the waisted years -I will find this city which does not exist - -There a hearth is burning for me -Like an eternal sign of forgotten truth -There is the last step till it -And this step is longer than the life - -There a hearth is burning for me -Like an eternal sign of forgotten truth -There is the last step till it -And this step is longer than the life \ No newline at end of file +of the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herbof the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb of the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb of the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb of the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb vvof the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb of the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb vvof the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb of the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb of the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb of the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb of the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb of the surface of the right-hand wall. Winston turned a switch and the voice sank somewhat, though the words were still distinguishable. The instrument (the telescreen, it was called) could be dimmed, but there was no way of shutting it off completely. He moved over to the window: a smallish, frail figure, the meagreness of his body merely emphasized by the blue overalls which were the uniform of the party. His hair was very fair, his face naturally sanguine, his skin roughened by coarse soap and blunt razor blades and the cold of the winter that had just ended. Outside, even through the shut window-pane, the world looked cold. Down in the street little eddies of wind were whirling dust and torn paper into spirals, and though the sun was shining and the sky a harsh blue, there seemed to be no colour in anything, except the posters that were plastered everywhere. The black-moustachio’d face gazed down from every commanding corner. There was one on the house-front immediately opposite. BIG BROTHER IS WATCHING YOU, the caption said, while the dark eyes looked deep into Winston’s own. Down at street level another poster, torn at one corner, flapped fitfully in the wind, alternately covering and uncovering the single word INGSOC. In the far distance a helicopter skimmed down between the roofs, hovered for an instant like a bluebottle, and darted away again with a curving flight. It was the police patrol, snooping into people’s windows. The patrols did not matter, however. Only the Thought Police mattered.Behind Winston’s back the voice from the telescreen was still babbling away about pig-iron and the overfulfilment of the Nith Three-Year Plan. The telescreen received and transmitted simultaneously. Any sound that Winston made, above the level of a very low whisper, would be picked up by it, moreover, so long as he remained within the field of vision which the metal plaque commanded, he could be seen as well as heard. There was of course no way of knowing whether you were being watched at any given moment. How often, or on what system, the Thought Police plugged in on any individual wire was guesswork. It was even conceivable that they watched everybody all the time. But at any rate they could plug in your wire whenever they wanted to. You had to live – did live, from habit that became instinct – in the assumption that every sound you made was overheard, and, except in darkness, every movement scrutinized.reg grgrgregreg ergregre fefefefefeif fewfeireier rrmfeifme grgoerigmreig gregrogmr grekgrggreignr rigmrmigmr rgmrgmrgimr rgmirgirmgmr grmirimgrmig rmgrigmirgmir rmgrigmrigrimg grigrmigrmg mrgrigrmigmig gr9gkrk9rg9kg9k gk9r9gkr9gk9gr vjvjvjirj rgorirk rereverivbreijvriv their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb their crazy garden walls sagging in all directions? And the bombed sites where the plaster dust swirled in the air and the willow-herb From eeb8fd4f61efbb3b6c5a2f50684e82a225497304 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 5 Dec 2021 15:49:23 +0300 Subject: [PATCH 13/17] changing the functions for working with the list --- .../SinglyLinkedListForHashTable.c" | 52 +++++++------------ .../SinglyLinkedListForHashTable.h" | 1 - .../TestSinglyLinkedListForHashTable.c" | 22 ++------ 3 files changed, 24 insertions(+), 51 deletions(-) diff --git "a/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c" "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c" index 358de4a..6c8cbd8 100644 --- "a/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c" +++ "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c" @@ -9,7 +9,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 +53,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,16 +69,20 @@ 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--; free(element->value); @@ -98,22 +106,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; @@ -164,22 +156,21 @@ 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; } - 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) @@ -196,9 +187,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; } } @@ -213,11 +204,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; diff --git "a/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" index 486e9ee..1e1d5f0 100644 --- "a/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" +++ "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" @@ -1,4 +1,3 @@ -#pragma once #include // Structure that represents list diff --git "a/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c" "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c" index 25bcb12..d6d550c 100644 --- "a/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/TestSinglyLinkedListForHashTable.c" +++ "b/Homework \342\204\226 9/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; } @@ -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 48247b90c2b4ea96820fa1b764ce9776d24f5c61 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 5 Dec 2021 15:53:32 +0300 Subject: [PATCH 14/17] changing functions to work with a hash table --- .../HashTable/HashTable/HashTable.c" | 51 +++++-------------- .../HashTable/HashTable/HashTable.h" | 4 +- .../HashTable/HashTable/TestHashTable.c" | 10 ++-- 3 files changed, 21 insertions(+), 44 deletions(-) diff --git "a/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" index bb25cfc..a177f51 100644 --- "a/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" +++ "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" @@ -10,7 +10,7 @@ typedef struct HashTable struct List** array; } HashTable; -HashTable* createTable(Error* error) +HashTable* createTable(Error* error, int numberOfSegment) { if (*error != NOT_ERROR) { @@ -22,8 +22,8 @@ HashTable* createTable(Error* error) *error = INSUFFICIENT_MEMORY; return NULL; } - table->numberOfSegment = 100; - table->array = calloc(100, sizeof(List*)); + table->numberOfSegment = numberOfSegment; + table->array = calloc(table->numberOfSegment, sizeof(List*)); if (table->array == NULL) { free(table); @@ -58,7 +58,7 @@ int hashFunction(const char* string, HashTable* table) { result = (result + string[i]) % table->numberOfSegment; } - return result; + return abs(result); } HashTable* resize(HashTable* table, Error* error) @@ -67,30 +67,7 @@ HashTable* resize(HashTable* table, Error* error) { return table; } - HashTable* newTable = calloc(1, sizeof(HashTable)); - if (newTable == NULL) - { - *error = INSUFFICIENT_MEMORY; - return table; - } - newTable->numberOfSegment = table->numberOfSegment * 2; - newTable->array = calloc(newTable->numberOfSegment, sizeof(List*)); - if (newTable->array == NULL) - { - free(newTable); - *error = INSUFFICIENT_MEMORY; - return table; - } - for (int i = 0; i < newTable->numberOfSegment; i++) - { - newTable->array[i] = createList(error); - if (*error != NOT_ERROR) - { - *error = INSUFFICIENT_MEMORY; - deleteHashTable(newTable); - break; - } - } + HashTable* newTable = createTable(error, table->numberOfSegment * 2); for (int i = 0; i < table->numberOfSegment; i++) { while (!isEmpty(table->array[i])) @@ -114,29 +91,29 @@ HashTable* resize(HashTable* table, Error* error) return newTable; } -void addElement(const char* string, HashTable* table, Error* error) +void addElement(const char* string, HashTable** table, Error* error) { if (*error != NOT_ERROR) { return; } - float factor = (float)(table->numberOfElements) / (float)(table->numberOfSegment); - if (factor > 1.5) + float factor = (float)((*table)->numberOfElements) / (float)((*table)->numberOfSegment); + if (factor > 1) { - table = resize(table, error); + *table = resize(*table, error); if (*error != NOT_ERROR) { return; } } - add(table->array[hashFunction(string, table)], string, error); + add((*table)->array[hashFunction(string, *table)], string, error); if (*error == INSUFFICIENT_MEMORY) { return; } if (*error != ELEMENT_REPEATS) { - table->numberOfElements++; + (*table)->numberOfElements++; return; } error = NOT_ERROR; @@ -145,14 +122,14 @@ void addElement(const char* string, HashTable* table, Error* error) void printValue(HashTable* table) { int maximumListLength = numberOfElements(table->array[0]); - int numberOfompletedBuckets = 0; + int numberOf?ompletedBuckets = 0; int totalSizeOfAllLists = 0; for (int i = 0; i < table->numberOfSegment; i++) { print(table->array[i]); if (!isEmpty(table->array[i])) { - numberOfompletedBuckets++; + numberOf?ompletedBuckets++; } int listLength = numberOfElements(table->array[i]); totalSizeOfAllLists += listLength; @@ -163,7 +140,7 @@ void printValue(HashTable* table) } printf("maximum list lenght = %d\n", maximumListLength); printf("hash table fill factor = %f\n", (float)(table->numberOfElements) / (float)(table->numberOfSegment)); - printf("average list length = %f\n", (float)(totalSizeOfAllLists) / (float)(numberOfompletedBuckets)); + printf("average list length = %f\n", (float)(totalSizeOfAllLists) / (float)(numberOf?ompletedBuckets)); } bool inTable(HashTable* table, char* string) diff --git "a/Homework \342\204\226 9/HashTable/HashTable/HashTable.h" "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.h" index 5421bad..e18aaad 100644 --- "a/Homework \342\204\226 9/HashTable/HashTable/HashTable.h" +++ "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.h" @@ -5,13 +5,13 @@ typedef struct HashTable HashTable; // Function for creating a hash table -HashTable* createTable(Error* error); +HashTable* createTable(Error* error, int numberOfBuckets); // Function for deleting a hash table void deleteHashTable(HashTable* table); // Function for adding an element to a hash table -void addElement(const char* string, HashTable* table, Error* error); +void addElement(const char* string, HashTable** table, Error* error); // Function for printing values void printValue(HashTable* table); diff --git "a/Homework \342\204\226 9/HashTable/HashTable/TestHashTable.c" "b/Homework \342\204\226 9/HashTable/HashTable/TestHashTable.c" index b7fbdc7..cfe5b1f 100644 --- "a/Homework \342\204\226 9/HashTable/HashTable/TestHashTable.c" +++ "b/Homework \342\204\226 9/HashTable/HashTable/TestHashTable.c" @@ -4,13 +4,13 @@ bool testAddElement() { Error error = NOT_ERROR; - HashTable* table = createTable(&error); - addElement("Hello", table, &error); - addElement("World", table, &error); - addElement("Test", table, &error); + HashTable* table = createTable(&error, 10); + addElement("Hello", &table, &error); + addElement("World", &table, &error); + addElement("Test", &table, &error); bool firstResult = inTable(table, "Hello"); bool secondResult = inTable(table, "World"); bool thirdResult = inTable(table, "Test"); deleteHashTable(table); - return firstResult && secondResult && thirdResult; + return firstResult && secondResult && thirdResult; } \ No newline at end of file From 63cb7e23bbcd90ef9770184c6511c5275f2de542 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 5 Dec 2021 18:03:01 +0300 Subject: [PATCH 15/17] changing functions to work with a hash table --- .../SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" | 1 + 1 file changed, 1 insertion(+) diff --git "a/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" index 1e1d5f0..486e9ee 100644 --- "a/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" +++ "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" @@ -1,3 +1,4 @@ +#pragma once #include // Structure that represents list From 1ed2aceeb6fb1d6fc3456115d4744fdb1fe29eba Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Wed, 8 Dec 2021 11:56:25 +0300 Subject: [PATCH 16/17] changing the shortcomings in the functions for the hash table --- .../FrequencyOfOccurrenceOfWords.c" | 2 +- .../FrequencyOfOccurrenceOfWords.vcxproj" | 2 +- .../FrequencyOfOccurrenceOfWords/ReadFile.c" | 2 +- .../TestReadFileUsingHashTable.c" | 2 +- .../HashTable/HashTable/HashTable.c" | 24 +++++++------------ .../SinglyLinkedListForHashTable.c" | 7 +----- 6 files changed, 14 insertions(+), 25 deletions(-) diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" index f9a27bd..5f0eb49 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" @@ -9,7 +9,7 @@ int main() return -1; } Error error = NOT_ERROR; - HashTable* table = createTable(&error); + HashTable* table = createTable(&error, 200); int result = readFile(&table, "Text.txt"); if (result == -1) { diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.vcxproj" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.vcxproj" index d4c299f..555090a 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.vcxproj" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.vcxproj" @@ -114,7 +114,7 @@ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" index c449751..e76b231 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/ReadFile.c" @@ -13,7 +13,7 @@ int readFile(HashTable** table, const char* fileName) // words in the file are less than 100 characters in size char array[100] = { '\0' }; Error error = NOT_ERROR; - if (fscanf(file, "%s", array) != EOF); + if (fscanf(file, "%s", array) != EOF) { addElement(array, table, &error); if (error == INSUFFICIENT_MEMORY) diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" index c6c273f..fbd35de 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/TestReadFileUsingHashTable.c" @@ -4,7 +4,7 @@ bool testReadFileUsingHashTable() { Error error = NOT_ERROR; - HashTable* table = createTable(&error); + HashTable* table = createTable(&error, 100); int result = readFile(&table, "Test.txt"); if (result == -1) { diff --git "a/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" index a177f51..6421e76 100644 --- "a/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" +++ "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" @@ -23,14 +23,14 @@ HashTable* createTable(Error* error, int numberOfSegment) return NULL; } table->numberOfSegment = numberOfSegment; - table->array = calloc(table->numberOfSegment, sizeof(List*)); + table->array = calloc(numberOfSegment, sizeof(List*)); if (table->array == NULL) { free(table); *error = INSUFFICIENT_MEMORY; return NULL; } - for (int i = 0; i < table->numberOfSegment; i++) + for (int i = 0; i < numberOfSegment; i++) { table->array[i] = createList(error); if (*error != NOT_ERROR) @@ -68,22 +68,16 @@ HashTable* resize(HashTable* table, Error* error) return table; } HashTable* newTable = createTable(error, table->numberOfSegment * 2); - for (int i = 0; i < table->numberOfSegment; i++) + int i = 0; + while (i < table->numberOfSegment) { while (!isEmpty(table->array[i])) { - char* newString = calloc(strlen(getHeadValue(table->array[i])) + 1, sizeof(char)); - if (newString == NULL) - { - *error = INSUFFICIENT_MEMORY; - deleteHashTable(newTable); - return table; - } - strcpy(newString, getHeadValue(table->array[i])); - add(newTable->array[i], newString, error); + add(newTable->array[i], getHeadValue(table->array[i]), error); removeFirstElement(table->array[i], error); } deleteList(table->array[i]); + i++; } newTable->numberOfElements = table->numberOfElements; free(table->array); @@ -122,14 +116,14 @@ void addElement(const char* string, HashTable** table, Error* error) void printValue(HashTable* table) { int maximumListLength = numberOfElements(table->array[0]); - int numberOf?ompletedBuckets = 0; + int numberOfCompletedBuckets = 0; int totalSizeOfAllLists = 0; for (int i = 0; i < table->numberOfSegment; i++) { print(table->array[i]); if (!isEmpty(table->array[i])) { - numberOf?ompletedBuckets++; + numberOfCompletedBuckets++; } int listLength = numberOfElements(table->array[i]); totalSizeOfAllLists += listLength; @@ -140,7 +134,7 @@ void printValue(HashTable* table) } printf("maximum list lenght = %d\n", maximumListLength); printf("hash table fill factor = %f\n", (float)(table->numberOfElements) / (float)(table->numberOfSegment)); - printf("average list length = %f\n", (float)(totalSizeOfAllLists) / (float)(numberOf?ompletedBuckets)); + printf("average list length = %f\n", (float)(totalSizeOfAllLists) / (float)(numberOfCompletedBuckets)); } bool inTable(HashTable* table, char* string) diff --git "a/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c" "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c" index 6c8cbd8..54dc4dd 100644 --- "a/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c" +++ "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.c" @@ -69,7 +69,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); @@ -112,11 +112,6 @@ Position* next(Position* position) return position; } -bool isLastElement(Position* position) -{ - return position->position->next == NULL; -} - int numberOfElements(List* list) { return list->size; From 5d5eb3491706541eb54eb19859b0915397b3d479 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Wed, 8 Dec 2021 15:47:12 +0300 Subject: [PATCH 17/17] changed the function for expanding the hash table --- .../FrequencyOfOccurrenceOfWords.c" | 2 +- "Homework \342\204\226 9/HashTable/HashTable/HashTable.c" | 3 ++- .../SinglyLinkedListForHashTable.h" | 3 --- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" index 5f0eb49..207c694 100644 --- "a/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" +++ "b/Homework \342\204\226 9/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords/FrequencyOfOccurrenceOfWords.c" @@ -9,7 +9,7 @@ int main() return -1; } Error error = NOT_ERROR; - HashTable* table = createTable(&error, 200); + HashTable* table = createTable(&error, 1); int result = readFile(&table, "Text.txt"); if (result == -1) { diff --git "a/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" index 6421e76..e253802 100644 --- "a/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" +++ "b/Homework \342\204\226 9/HashTable/HashTable/HashTable.c" @@ -73,7 +73,8 @@ HashTable* resize(HashTable* table, Error* error) { while (!isEmpty(table->array[i])) { - add(newTable->array[i], getHeadValue(table->array[i]), error); + add(newTable->array[hashFunction(getHeadValue(table->array[i]), table)], getHeadValue(table->array[i]), error); + *error = NOT_ERROR; removeFirstElement(table->array[i], error); } deleteList(table->array[i]); diff --git "a/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" index 486e9ee..118b596 100644 --- "a/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" +++ "b/Homework \342\204\226 9/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable/SinglyLinkedListForHashTable.h" @@ -34,9 +34,6 @@ 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);