-
Notifications
You must be signed in to change notification settings - Fork 0
sadness #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MinyazevR
wants to merge
1
commit into
main
Choose a base branch
from
Control2Task2Attempt2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
sadness #76
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 16 | ||
| VisualStudioVersion = 16.0.31410.357 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "List", "List\List.vcxproj", "{721388A3-2CFA-44FE-915A-0A846DB709F4}" | ||
| 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 | ||
| {721388A3-2CFA-44FE-915A-0A846DB709F4}.Debug|x64.ActiveCfg = Debug|x64 | ||
| {721388A3-2CFA-44FE-915A-0A846DB709F4}.Debug|x64.Build.0 = Debug|x64 | ||
| {721388A3-2CFA-44FE-915A-0A846DB709F4}.Debug|x86.ActiveCfg = Debug|Win32 | ||
| {721388A3-2CFA-44FE-915A-0A846DB709F4}.Debug|x86.Build.0 = Debug|Win32 | ||
| {721388A3-2CFA-44FE-915A-0A846DB709F4}.Release|x64.ActiveCfg = Release|x64 | ||
| {721388A3-2CFA-44FE-915A-0A846DB709F4}.Release|x64.Build.0 = Release|x64 | ||
| {721388A3-2CFA-44FE-915A-0A846DB709F4}.Release|x86.ActiveCfg = Release|Win32 | ||
| {721388A3-2CFA-44FE-915A-0A846DB709F4}.Release|x86.Build.0 = Release|Win32 | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {E12AB49D-6742-4F31-87F2-2C61C86207CE} | ||
| EndGlobalSection | ||
| EndGlobal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| #define _CRT_SECURE_NO_WARNINGS | ||
| #include "List.h" | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <malloc.h> | ||
| #include <stdlib.h> | ||
|
|
||
| // 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 | ||
| { | ||
| char* value; | ||
| struct ListElement* next; | ||
| } ListElement; | ||
|
|
||
| // Structure containing a pointer to a ListElement | ||
| typedef struct Position | ||
| { | ||
| ListElement* position; | ||
| } Position; | ||
|
|
||
| List* createList(Error* error) | ||
| { | ||
| List* list = calloc(1, sizeof(List)); | ||
| if (list == NULL) | ||
| { | ||
| *error = INSUFFICIENT_MEMORY; | ||
| } | ||
| return list; | ||
| } | ||
|
|
||
| void deleteList(List* list) | ||
| { | ||
| ListElement* position = list->head; | ||
| while (position != NULL) | ||
| { | ||
| list->head = list->head->next; | ||
| free(position->value); | ||
| free(position); | ||
| position = list->head; | ||
| } | ||
| free(list); | ||
| } | ||
|
|
||
| void deletePosition(Position* position) | ||
| { | ||
| free(position); | ||
| } | ||
|
|
||
| void removeFirstElement(List* list, Error* error) | ||
| { | ||
| if (*error != NOT_ERROR) | ||
| { | ||
| return; | ||
| } | ||
| if (list->head == NULL) | ||
| { | ||
| *error = EMPTY_LIST; | ||
| return; | ||
| } | ||
| if (list->head == list->tail) | ||
| { | ||
| list->size = 0; | ||
| free(list->head->value); | ||
| free(list->head); | ||
| list->head = NULL; | ||
| list->tail = NULL; | ||
| return; | ||
| } | ||
| ListElement* element = list->head; | ||
| list->head = list->head->next; | ||
| list->size--; | ||
| free(element->value); | ||
| free(element); | ||
|
|
||
| } | ||
|
|
||
| Position* first(List* list, Error* error) | ||
| { | ||
| if (*error != NOT_ERROR) | ||
| { | ||
| return NULL; | ||
| } | ||
| Position* positionFirst = malloc(sizeof(Position)); | ||
| if (positionFirst == NULL) | ||
| { | ||
| *error = EMPTY_LIST; | ||
| return NULL; | ||
| } | ||
| positionFirst->position = list->head; | ||
| return positionFirst; | ||
| } | ||
|
|
||
| Position* last(List* list, Error* error) | ||
| { | ||
| if (*error != NOT_ERROR) | ||
| { | ||
| return NULL; | ||
| } | ||
| Position* positionLast = malloc(sizeof(Position)); | ||
| if (positionLast == NULL) | ||
| { | ||
| *error = EMPTY_LIST; | ||
| return NULL; | ||
| } | ||
| positionLast->position = list->tail; | ||
| return positionLast; | ||
| } | ||
|
|
||
| Position* next(Position* position) | ||
| { | ||
| position->position = position->position->next; | ||
| return position; | ||
| } | ||
|
|
||
| bool isLastElement(Position* position) | ||
| { | ||
| return position->position->next == NULL; | ||
| } | ||
|
|
||
| int numberOfElements(List* list) | ||
| { | ||
| return list->size; | ||
| } | ||
|
|
||
| char* getHeadValue(List* list) | ||
| { | ||
| if (list->head == NULL) | ||
| { | ||
| return NULL; | ||
| } | ||
| return list->head->value; | ||
| } | ||
|
|
||
| void add(List* list, const char* value, Error* error) | ||
| { | ||
| if (*error != NOT_ERROR) | ||
| { | ||
| return; | ||
| } | ||
| 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; | ||
| if (list->head == NULL) | ||
| { | ||
| list->size = 1; | ||
| list->head = newElement; | ||
| list->tail = newElement; | ||
| return; | ||
| } | ||
| list->size++; | ||
| list->tail->next = newElement; | ||
| list->tail = list->tail->next; | ||
| } | ||
|
|
||
| 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\n", element->value); | ||
| element = element->next; | ||
| } | ||
| } | ||
|
|
||
| const char* decodingError(Error error) | ||
| { | ||
| if (error == EMPTY_LIST) | ||
| { | ||
| return "Error in the program"; | ||
| } | ||
| if (error == INSUFFICIENT_MEMORY) | ||
| { | ||
| return "Memory not allocated"; | ||
| } | ||
| return NULL; | ||
| } | ||
|
|
||
| bool inList(List* list, const char* value) | ||
| { | ||
| ListElement* element = list->head; | ||
| while (element != NULL) | ||
| { | ||
| if (strcmp(value, element->value) == 0) | ||
| { | ||
| return true; | ||
| } | ||
| element = element->next; | ||
| } | ||
| return false; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #pragma once | ||
| #include <stdbool.h> | ||
|
|
||
| // Structure that represents list | ||
| typedef struct List List; | ||
|
|
||
| // This is a structure describing the position of an item in the list. | ||
| typedef struct Position Position; | ||
|
|
||
| // Enum type for working with errors | ||
| typedef enum Error | ||
| { | ||
| NOT_ERROR, | ||
| EMPTY_LIST, | ||
| INSUFFICIENT_MEMORY, | ||
| ELEMENT_REPEATS | ||
| } Error; | ||
|
|
||
| // Function for creating a list | ||
| List* createList(Error* error); | ||
|
|
||
| // Function for deleting a list | ||
| void deleteList(List* list); | ||
|
|
||
| // Function for freeing up memory | ||
| void deletePosition(Position* position); | ||
|
|
||
| // Function for adding an item to a list | ||
| void add(List* list, const char* value, Error* error); | ||
|
|
||
| // function to find a position to the first element | ||
| Position* first(List* list, Error* error); | ||
|
|
||
| // Function for finding a position to the next element | ||
| Position* next(Position* position); | ||
|
|
||
| // Function for checking an item for being at the end of the list | ||
| bool isLastElement(Position* position); | ||
|
|
||
| // Function for printing a list | ||
| void print(List* list); | ||
|
|
||
| // Function for deleting the first element | ||
| void removeFirstElement(List* list, Error* error); | ||
|
|
||
| // Function for finding the number of items in the list | ||
| int numberOfElements(List* list); | ||
|
|
||
| // Function for checking the emptiness of the list | ||
| bool isEmpty(List* list); | ||
|
|
||
| // Function that returns a value for the first element | ||
| char* getHeadValue(List* list); | ||
|
|
||
| // Function that returns a value of element | ||
| char* getValue(Position* position); | ||
|
|
||
| // Function for error decoding | ||
| const char* decodingError(Error error); | ||
|
|
||
| // Function for determining the location of an item in the list | ||
| bool inList(List* list, const char* value); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.