From 92d37a183284271c5a2564185b21fc63f5cc6e05 Mon Sep 17 00:00:00 2001 From: Artem Date: Mon, 24 Oct 2022 09:50:00 +0300 Subject: [PATCH 01/10] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BC=D0=BE=D0=B4=D0=B8=D1=84=D0=B8=D1=86=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20=D1=81=D1=82=D0=B5?= =?UTF-8?q?=D0=BA=20=D0=B8=20=D0=BE=D1=87=D0=B5=D1=80=D0=B5=D0=B4=D1=8C,?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5?= =?UTF-8?q?=20=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sortStation/sortStation.sln | 31 ++++ sortStation/sortStation/main.c | 0 sortStation/sortStation/queue.c | 64 ++++++++ sortStation/sortStation/queue.h | 20 +++ sortStation/sortStation/sortStation.vcxproj | 150 ++++++++++++++++++ .../sortStation/sortStation.vcxproj.filters | 17 ++ sortStation/sortStation/stack.c | 70 ++++++++ sortStation/sortStation/stack.h | 24 +++ 8 files changed, 376 insertions(+) create mode 100644 sortStation/sortStation.sln create mode 100644 sortStation/sortStation/main.c create mode 100644 sortStation/sortStation/queue.c create mode 100644 sortStation/sortStation/queue.h create mode 100644 sortStation/sortStation/sortStation.vcxproj create mode 100644 sortStation/sortStation/sortStation.vcxproj.filters create mode 100644 sortStation/sortStation/stack.c create mode 100644 sortStation/sortStation/stack.h diff --git a/sortStation/sortStation.sln b/sortStation/sortStation.sln new file mode 100644 index 0000000..3b3d18f --- /dev/null +++ b/sortStation/sortStation.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sortStation", "sortStation\sortStation.vcxproj", "{6E239FD9-AD88-4EA0-B69A-CC5CF6417AD7}" +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 + {6E239FD9-AD88-4EA0-B69A-CC5CF6417AD7}.Debug|x64.ActiveCfg = Debug|x64 + {6E239FD9-AD88-4EA0-B69A-CC5CF6417AD7}.Debug|x64.Build.0 = Debug|x64 + {6E239FD9-AD88-4EA0-B69A-CC5CF6417AD7}.Debug|x86.ActiveCfg = Debug|Win32 + {6E239FD9-AD88-4EA0-B69A-CC5CF6417AD7}.Debug|x86.Build.0 = Debug|Win32 + {6E239FD9-AD88-4EA0-B69A-CC5CF6417AD7}.Release|x64.ActiveCfg = Release|x64 + {6E239FD9-AD88-4EA0-B69A-CC5CF6417AD7}.Release|x64.Build.0 = Release|x64 + {6E239FD9-AD88-4EA0-B69A-CC5CF6417AD7}.Release|x86.ActiveCfg = Release|Win32 + {6E239FD9-AD88-4EA0-B69A-CC5CF6417AD7}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3014B97C-51B5-43EE-9278-48A66DA4321D} + EndGlobalSection +EndGlobal diff --git a/sortStation/sortStation/main.c b/sortStation/sortStation/main.c new file mode 100644 index 0000000..e69de29 diff --git a/sortStation/sortStation/queue.c b/sortStation/sortStation/queue.c new file mode 100644 index 0000000..d5f5422 --- /dev/null +++ b/sortStation/sortStation/queue.c @@ -0,0 +1,64 @@ +#include "queue.h" +#include +#include +#include + +int enqueue(Queue* queue, char value[]) { + Node* temp = malloc(sizeof(Node)); + if (temp == NULL) { + printf("Problems with memory allocation"); + return -1; + } + size_t sizeValue = strlen(value); + strncpy(temp->value, value, sizeValue); + temp->next = NULL; + + if (queue->tail == NULL) { + queue->tail = temp; + queue->head = temp; + } + else { + queue->tail->next = temp; + queue->tail = temp; + } + + return 0; +} + +char* dequeue(Queue* queue, int* errorCode) { + if (queue->head == NULL) { + if (errorCode != NULL) { + *errorCode = -1; + } + + return 0; + } + if (errorCode != NULL) { + *errorCode = 0; + } + + + char value[100] = { '\0' }; + size_t sizeQueueHeadValue = strlen(queue->head->value); + strncpy(value, queue->head->value, sizeQueueHeadValue); + + Node* next = queue->head->next; + free(queue->head); + queue->head = next; + if (next == NULL) { + queue->tail = NULL; + } + + return value; +} + +bool isEmptyQueue(Queue queue) { + return queue.head == NULL; +} + +void clear(Queue* queue) { + while (!isEmptyQueue(*queue)) { + int errorCode = 0; + dequeue(queue, &errorCode); + } +} \ No newline at end of file diff --git a/sortStation/sortStation/queue.h b/sortStation/sortStation/queue.h new file mode 100644 index 0000000..6ac237a --- /dev/null +++ b/sortStation/sortStation/queue.h @@ -0,0 +1,20 @@ +#pragma once +#include + +typedef struct Node { + char value[100]; + struct Node* next; +} Node; + +typedef struct Queue { + struct Node* head; + struct Node* tail; +} Queue; + +int enqueue(Queue* queue, char value[]); + +char* dequeue(Queue* queue, int* errorCode); + +bool isEmptyQueue(Queue queue); + +void clear(Queue* queue); \ No newline at end of file diff --git a/sortStation/sortStation/sortStation.vcxproj b/sortStation/sortStation/sortStation.vcxproj new file mode 100644 index 0000000..595a46f --- /dev/null +++ b/sortStation/sortStation/sortStation.vcxproj @@ -0,0 +1,150 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + 16.0 + Win32Proj + {6e239fd9-ad88-4ea0-b69a-cc5cf6417ad7} + sortStation + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + diff --git a/sortStation/sortStation/sortStation.vcxproj.filters b/sortStation/sortStation/sortStation.vcxproj.filters new file mode 100644 index 0000000..153170c --- /dev/null +++ b/sortStation/sortStation/sortStation.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {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/sortStation/sortStation/stack.c b/sortStation/sortStation/stack.c new file mode 100644 index 0000000..6f95e1b --- /dev/null +++ b/sortStation/sortStation/stack.c @@ -0,0 +1,70 @@ +#include "stack.h" +#include +#include + +typedef struct Node { + char value; + struct Node* next; +} Node; + +typedef struct Stack { + Node* head; +} Stack; + +int push(Stack* stack, char value) { + Node* temp = malloc(sizeof(Node)); + if (temp == NULL) { + printf("Problems with memory allocation"); + return -1; + } + temp->value = value; + temp->next = stack->head; + + stack->head = temp; + return 0; +} + +char pop(Stack* stack, int* errorCode) { + if (stack->head == NULL) { + if (errorCode != NULL) { + *errorCode = -1; + } + + return 0; + } + if (errorCode != NULL) { + *errorCode = 0; + } + + char value = stack->head->value; + + Stack* next = stack->head->next; + free(stack->head); + stack->head = next; + + return value; +} + +bool isEmpty(Stack* stack) { + return stack->head == NULL; +} + +void deleteStack(Stack* stack) { + while (!isEmpty(stack)) { + int errorCode = 0; + pop(stack, &errorCode); + } +} + +Stack* createStack(void) { + Stack* stack = malloc(sizeof(Stack)); + stack->head = NULL; + return stack; +} + +char top(Stack* stack) { + if (stack->head == NULL) { + return ""; + } + return stack->head->value; +} \ No newline at end of file diff --git a/sortStation/sortStation/stack.h b/sortStation/sortStation/stack.h new file mode 100644 index 0000000..280a991 --- /dev/null +++ b/sortStation/sortStation/stack.h @@ -0,0 +1,24 @@ +#ifndef _STACK_H +#define _STACK_H +#include + +typedef struct Stack Stack; + +// +int push(Stack* stack, char value); + +// +char pop(Stack* stack, int* errorCode); + +// +bool isEmpty(Stack* stack); + +// +void deleteStack(Stack* stack); + +// +Stack* createStack(void); + +// +char top(Stack* stack); +#endif \ No newline at end of file From 687eea7924a53ae9927bcedd65fb7a9d1e735331 Mon Sep 17 00:00:00 2001 From: Artem Date: Mon, 24 Oct 2022 09:53:22 +0300 Subject: [PATCH 02/10] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20ma?= =?UTF-8?q?in?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sortStation/sortStation/main.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/sortStation/sortStation/main.c b/sortStation/sortStation/main.c index e69de29..7b4cf91 100644 --- a/sortStation/sortStation/main.c +++ b/sortStation/sortStation/main.c @@ -0,0 +1,22 @@ +#include +#include +#include "stack.h" +#include "queue.h" +#include +#include + +bool converterToPostfixForm(char buffer[], char result[]) { + + return true; +} + + +int main() { + setlocale(LC_ALL, "RUS"); + printf(" \n"); + char buffer[100] = { '\0' }; + gets_s(buffer, 100); + char result[100] = { '\0' }; + converterToPostfixForm(buffer, result); + printf("%s", result); +} \ No newline at end of file From b43c2e39a55be1ddcf6238f4f8b8ec5ee4cfbcdb Mon Sep 17 00:00:00 2001 From: Artem Date: Mon, 24 Oct 2022 14:51:53 +0300 Subject: [PATCH 03/10] =?UTF-8?q?=D0=9D=D0=B0=D0=BF=D0=B8=D1=81=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80=D0=B8=D1=82=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sortStation/sortStation/main.c | 120 +++++++++++++++++- sortStation/sortStation/queue.c | 17 +-- sortStation/sortStation/queue.h | 2 +- sortStation/sortStation/sortStation.vcxproj | 45 ++++--- .../sortStation/sortStation.vcxproj.filters | 19 +++ sortStation/sortStation/stack.c | 3 +- 6 files changed, 172 insertions(+), 34 deletions(-) diff --git a/sortStation/sortStation/main.c b/sortStation/sortStation/main.c index 7b4cf91..c81edc2 100644 --- a/sortStation/sortStation/main.c +++ b/sortStation/sortStation/main.c @@ -6,7 +6,118 @@ #include bool converterToPostfixForm(char buffer[], char result[]) { - + size_t sizeBuffer = strlen(buffer); + Queue queue = { NULL, NULL }; + Stack* operatorActions = createStack(); + size_t i = 0; + int errorCode = 0; + char number[100] = { '\0' }; + while (i < sizeBuffer) { + memset(number, 0, strlen(number)); + int walker = 0; + while (buffer[i] >= '0' && buffer[i] <= '9') { + number[walker] = buffer[i]; + ++i; + ++walker; + } + if (strlen(number) != 0) { + enqueue(&queue, number); + } + if (buffer[i] == '*' || buffer[i] == '+' || buffer[i] == '/' || buffer[i] == '-' || buffer[i] == '(' || buffer[i] == ')') { + if (isEmpty(operatorActions)) { + push(operatorActions, buffer[i]); + } + else if (buffer[i] == '(') { + push(operatorActions, buffer[i]); + } + else if (top(operatorActions) == '(') { + push(operatorActions, buffer[i]); + } + else if (buffer[i] == ')') { + while (!isEmpty(operatorActions)) { + char operations = pop(operatorActions, &errorCode); + char symbol[2] = { '\0' }; + symbol[0] = operations; + if (errorCode != 0) { + return false; + } + if (operations != '(') { + enqueue(&queue, symbol); + } + } + } + else if (buffer[i] == '*' || buffer[i] == '/') { + if (top(operatorActions) == '/' || top(operatorActions) == '*') { + while (!isEmpty(operatorActions)) { + char operations = pop(operatorActions, &errorCode); + char symbol[2] = { '\0' }; + symbol[0] = operations; + if (errorCode != 0) { + return false; + } + if (operations != '(') { + enqueue(&queue, symbol); + } + } + } + push(operatorActions, buffer[i]); + } + else if (buffer[i] == '+' || buffer[i] == '-') { + while (!isEmpty(operatorActions)) { + char operations = pop(operatorActions, &errorCode); + char symbol[2] = { '\0' }; + symbol[0] = operations; + if (errorCode != 0) { + return false; + } + if (operations != '(') { + enqueue(&queue, symbol); + } + } + push(operatorActions, buffer[i]); + } + } + ++i; + } + while (!isEmpty(operatorActions)) { + char operations = pop(operatorActions, &errorCode); + if (errorCode != 0) { + return false; + } + char symbol[2] = { '\0' }; + symbol[0] = operations; + if (operations != '(') { + enqueue(&queue, symbol); + } + } + size_t j = 0; + while (!isEmptyQueue(queue)) { + char queueElements[100] = { '\0' }; + dequeue(&queue, &errorCode, queueElements); + if (errorCode != 0) { + return false; + } + size_t sizeQueueElements = strlen(queueElements); + size_t i = 0; + while (i < sizeQueueElements) { + result[j] = queueElements[i]; + ++i; + ++j; + } + result[j] = ' '; + ++j; + } + if (!isEmptyQueue(queue)) { + clear(&queue); + return false; + } + if (operatorActions != NULL) { + if (!isEmpty(operatorActions)) { + deleteStack(operatorActions); + return false; + } + deleteStack(operatorActions); + } return true; } @@ -17,6 +128,9 @@ int main() { char buffer[100] = { '\0' }; gets_s(buffer, 100); char result[100] = { '\0' }; - converterToPostfixForm(buffer, result); - printf("%s", result); + if (converterToPostfixForm(buffer, result)) { + printf("%s", result); + } else { + printf(" ...\n"); + } } \ No newline at end of file diff --git a/sortStation/sortStation/queue.c b/sortStation/sortStation/queue.c index d5f5422..9fd8b41 100644 --- a/sortStation/sortStation/queue.c +++ b/sortStation/sortStation/queue.c @@ -4,12 +4,13 @@ #include int enqueue(Queue* queue, char value[]) { - Node* temp = malloc(sizeof(Node)); + Node* temp = calloc(1, sizeof(Node)); if (temp == NULL) { printf("Problems with memory allocation"); return -1; } size_t sizeValue = strlen(value); + memset(temp->value, 0, strlen(temp->value)); strncpy(temp->value, value, sizeValue); temp->next = NULL; @@ -25,7 +26,7 @@ int enqueue(Queue* queue, char value[]) { return 0; } -char* dequeue(Queue* queue, int* errorCode) { +void dequeue(Queue* queue, int* errorCode, char value[]) { if (queue->head == NULL) { if (errorCode != NULL) { *errorCode = -1; @@ -37,19 +38,18 @@ char* dequeue(Queue* queue, int* errorCode) { *errorCode = 0; } - - char value[100] = { '\0' }; size_t sizeQueueHeadValue = strlen(queue->head->value); strncpy(value, queue->head->value, sizeQueueHeadValue); Node* next = queue->head->next; - free(queue->head); + //free(queue->head); + memset(queue->head->value, 0, strlen(queue->head->value)); + (queue->head)->next = NULL; + queue->head = NULL; queue->head = next; if (next == NULL) { queue->tail = NULL; } - - return value; } bool isEmptyQueue(Queue queue) { @@ -59,6 +59,7 @@ bool isEmptyQueue(Queue queue) { void clear(Queue* queue) { while (!isEmptyQueue(*queue)) { int errorCode = 0; - dequeue(queue, &errorCode); + dequeue(queue, &errorCode, ""); } + queue = NULL; } \ No newline at end of file diff --git a/sortStation/sortStation/queue.h b/sortStation/sortStation/queue.h index 6ac237a..9af3064 100644 --- a/sortStation/sortStation/queue.h +++ b/sortStation/sortStation/queue.h @@ -13,7 +13,7 @@ typedef struct Queue { int enqueue(Queue* queue, char value[]); -char* dequeue(Queue* queue, int* errorCode); +void dequeue(Queue* queue, int* errorCode, char value[]); bool isEmptyQueue(Queue queue); diff --git a/sortStation/sortStation/sortStation.vcxproj b/sortStation/sortStation/sortStation.vcxproj index 595a46f..a4d8ecd 100644 --- a/sortStation/sortStation/sortStation.vcxproj +++ b/sortStation/sortStation/sortStation.vcxproj @@ -17,7 +17,6 @@ Release x64 - 16.0 @@ -53,25 +52,23 @@ true Unicode - - + + + + + + + + + + + + + - - - - - - - - - - - - - true @@ -85,7 +82,6 @@ false - Level3 @@ -117,7 +113,7 @@ Level3 - true + false _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true @@ -142,9 +138,16 @@ true - - + + + + + + + + + - + \ No newline at end of file diff --git a/sortStation/sortStation/sortStation.vcxproj.filters b/sortStation/sortStation/sortStation.vcxproj.filters index 153170c..c9b034f 100644 --- a/sortStation/sortStation/sortStation.vcxproj.filters +++ b/sortStation/sortStation/sortStation.vcxproj.filters @@ -14,4 +14,23 @@ 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/sortStation/sortStation/stack.c b/sortStation/sortStation/stack.c index 6f95e1b..a7613f4 100644 --- a/sortStation/sortStation/stack.c +++ b/sortStation/sortStation/stack.c @@ -12,7 +12,7 @@ typedef struct Stack { } Stack; int push(Stack* stack, char value) { - Node* temp = malloc(sizeof(Node)); + Node* temp = calloc(1, sizeof(Node)); if (temp == NULL) { printf("Problems with memory allocation"); return -1; @@ -54,6 +54,7 @@ void deleteStack(Stack* stack) { int errorCode = 0; pop(stack, &errorCode); } + stack = NULL; } Stack* createStack(void) { From ac96d09441211a05009c7e84e33ba499155fa568 Mon Sep 17 00:00:00 2001 From: Artem Date: Mon, 24 Oct 2022 15:05:37 +0300 Subject: [PATCH 04/10] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20=D1=82=D0=B5=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sortStation/sortStation/main.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/sortStation/sortStation/main.c b/sortStation/sortStation/main.c index c81edc2..38fc567 100644 --- a/sortStation/sortStation/main.c +++ b/sortStation/sortStation/main.c @@ -121,9 +121,31 @@ bool converterToPostfixForm(char buffer[], char result[]) { return true; } +bool firstTest() { + char buffer[12] = { '(', '1', ' ', '+', ' ', '2', ')', ' ', '*', ' ', '2', '\0' }; + char arrayOutput[100] = { '\0' }; + if (!converterToPostfixForm(buffer, arrayOutput)) { + return false; + } + char bufferNew[10] = { '1', ' ', '2', ' ', '+', ' ', '2', ' ', '*', '\0' }; + size_t sizeArrayOutput = strlen(arrayOutput); + + for (int i = 0; i < sizeArrayOutput - 1; ++i) { + if (bufferNew[i] != arrayOutput[i]) { + printf("%c %c", bufferNew[i], arrayOutput[i]); + return false; + } + } + return true; +} int main() { setlocale(LC_ALL, "RUS"); + if (firstTest()) { + printf(" \n"); + } else { + printf(" ...\n"); + } printf(" \n"); char buffer[100] = { '\0' }; gets_s(buffer, 100); From c5ae79be9601d2c5f4b6853f32f43fda146f163a Mon Sep 17 00:00:00 2001 From: Artem Date: Mon, 24 Oct 2022 15:10:10 +0300 Subject: [PATCH 05/10] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20=D1=82=D0=B5=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sortStation/sortStation/main.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sortStation/sortStation/main.c b/sortStation/sortStation/main.c index 38fc567..6fbb405 100644 --- a/sortStation/sortStation/main.c +++ b/sortStation/sortStation/main.c @@ -132,7 +132,23 @@ bool firstTest() { for (int i = 0; i < sizeArrayOutput - 1; ++i) { if (bufferNew[i] != arrayOutput[i]) { - printf("%c %c", bufferNew[i], arrayOutput[i]); + return false; + } + } + return true; +} + +bool secondTest() { + char buffer[18] = { '(', '1', ' ', '+', ' ', '2', ')', ' ', '*', ' ', '(', '1', ' ', '+', ' ', '2', ')', '\0' }; + char arrayOutput[100] = { '\0' }; + if (!converterToPostfixForm(buffer, arrayOutput)) { + return false; + } + char bufferNew[14] = { '1', ' ', '2', ' ', '+', ' ', '1', ' ', '2', ' ', '+', ' ', '*', '\0' }; + size_t sizeArrayOutput = strlen(arrayOutput); + + for (int i = 0; i < sizeArrayOutput - 1; ++i) { + if (bufferNew[i] != arrayOutput[i]) { return false; } } @@ -141,7 +157,7 @@ bool firstTest() { int main() { setlocale(LC_ALL, "RUS"); - if (firstTest()) { + if (firstTest() && secondTest()) { printf(" \n"); } else { printf(" ...\n"); From f61200788f63be501d902ae15938de5a41abf69b Mon Sep 17 00:00:00 2001 From: Artem Date: Mon, 24 Oct 2022 15:24:38 +0300 Subject: [PATCH 06/10] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83,=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B3=D0=B4=D0=B0=20=D0=BD=D0=B0=D0=BF=D1=80=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D1=80=20=D0=B2=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=D1=85=20=D0=B8=D0=B4=D1=91=D1=82=20=D0=B7=D0=BD?= =?UTF-8?q?=D0=B0=D0=BA=20-,=20=D0=B0=20=D0=B7=D0=B0=D1=82=D0=B5=D0=BC=20*?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sortStation/sortStation/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sortStation/sortStation/main.c b/sortStation/sortStation/main.c index 6fbb405..2a5ecb0 100644 --- a/sortStation/sortStation/main.c +++ b/sortStation/sortStation/main.c @@ -48,7 +48,7 @@ bool converterToPostfixForm(char buffer[], char result[]) { } else if (buffer[i] == '*' || buffer[i] == '/') { if (top(operatorActions) == '/' || top(operatorActions) == '*') { - while (!isEmpty(operatorActions)) { + while (!isEmpty(operatorActions) && (top(operatorActions) == '/' || top(operatorActions) == '*')) { char operations = pop(operatorActions, &errorCode); char symbol[2] = { '\0' }; symbol[0] = operations; @@ -157,11 +157,13 @@ bool secondTest() { int main() { setlocale(LC_ALL, "RUS"); + if (firstTest() && secondTest()) { printf(" \n"); } else { printf(" ...\n"); } + printf(" \n"); char buffer[100] = { '\0' }; gets_s(buffer, 100); From f694ea60c145199f7a0dec4555c8920b0bc34d8d Mon Sep 17 00:00:00 2001 From: Palezehvat <114094069+Palezehvat@users.noreply.github.com> Date: Fri, 18 Nov 2022 14:44:13 +0300 Subject: [PATCH 07/10] Delete HomeworksAccept directory --- HomeworksAccept/homework21.09/read.me | 1 - HomeworksAccept/homework28.09/read.me | 1 - HomeworksAccept/read.me | 1 - 3 files changed, 3 deletions(-) delete mode 100644 HomeworksAccept/homework21.09/read.me delete mode 100644 HomeworksAccept/homework28.09/read.me delete mode 100644 HomeworksAccept/read.me diff --git a/HomeworksAccept/homework21.09/read.me b/HomeworksAccept/homework21.09/read.me deleted file mode 100644 index 5e4d090..0000000 --- a/HomeworksAccept/homework21.09/read.me +++ /dev/null @@ -1 +0,0 @@ -3 домашка diff --git a/HomeworksAccept/homework28.09/read.me b/HomeworksAccept/homework28.09/read.me deleted file mode 100644 index 5061ad0..0000000 --- a/HomeworksAccept/homework28.09/read.me +++ /dev/null @@ -1 +0,0 @@ -4 домашка diff --git a/HomeworksAccept/read.me b/HomeworksAccept/read.me deleted file mode 100644 index 1773bf8..0000000 --- a/HomeworksAccept/read.me +++ /dev/null @@ -1 +0,0 @@ -Здесь представлены домашнии работы, прошедшии проверку From c99aa3bbf8a45f3f038e7710cab69e091b103615 Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 23 Dec 2022 11:43:54 +0300 Subject: [PATCH 08/10] =?UTF-8?q?=D0=A0=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sortStation/sortStation/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sortStation/sortStation/main.c b/sortStation/sortStation/main.c index 2a5ecb0..74a4d9b 100644 --- a/sortStation/sortStation/main.c +++ b/sortStation/sortStation/main.c @@ -5,7 +5,7 @@ #include #include -bool converterToPostfixForm(char buffer[], char result[]) { +bool converterToPostfixForm(const char buffer[], char result[]) { size_t sizeBuffer = strlen(buffer); Queue queue = { NULL, NULL }; Stack* operatorActions = createStack(); From 2819fd8a39508409b6283c6bab75a354c1e341d1 Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 23 Dec 2022 14:34:42 +0300 Subject: [PATCH 09/10] =?UTF-8?q?=D0=A0=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sortStation/sortStation/main.c | 53 ++++++++++++++++----------------- sortStation/sortStation/stack.c | 8 ++--- sortStation/sortStation/stack.h | 3 +- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/sortStation/sortStation/main.c b/sortStation/sortStation/main.c index 74a4d9b..c68158d 100644 --- a/sortStation/sortStation/main.c +++ b/sortStation/sortStation/main.c @@ -5,6 +5,19 @@ #include #include +void returnOperation(Stack* operatorActions, char symbol[], int* errorCode, Queue* queue) { + char operations = pop(operatorActions, errorCode); + symbol[0] = operations; + if (*errorCode != 0) { + clear(queue); + deleteStack(&operatorActions); + return false; + } + if (operations != '(') { + enqueue(queue, symbol); + } +} + bool converterToPostfixForm(const char buffer[], char result[]) { size_t sizeBuffer = strlen(buffer); Queue queue = { NULL, NULL }; @@ -35,44 +48,32 @@ bool converterToPostfixForm(const char buffer[], char result[]) { } else if (buffer[i] == ')') { while (!isEmpty(operatorActions)) { - char operations = pop(operatorActions, &errorCode); char symbol[2] = { '\0' }; - symbol[0] = operations; + returnOperation(operatorActions, symbol, &errorCode, &queue); if (errorCode != 0) { return false; } - if (operations != '(') { - enqueue(&queue, symbol); - } } } else if (buffer[i] == '*' || buffer[i] == '/') { if (top(operatorActions) == '/' || top(operatorActions) == '*') { while (!isEmpty(operatorActions) && (top(operatorActions) == '/' || top(operatorActions) == '*')) { - char operations = pop(operatorActions, &errorCode); char symbol[2] = { '\0' }; - symbol[0] = operations; + returnOperation(operatorActions, symbol, &errorCode, &queue); if (errorCode != 0) { return false; } - if (operations != '(') { - enqueue(&queue, symbol); - } } } push(operatorActions, buffer[i]); } else if (buffer[i] == '+' || buffer[i] == '-') { while (!isEmpty(operatorActions)) { - char operations = pop(operatorActions, &errorCode); char symbol[2] = { '\0' }; - symbol[0] = operations; + returnOperation(operatorActions, symbol, &errorCode, &queue); if (errorCode != 0) { return false; } - if (operations != '(') { - enqueue(&queue, symbol); - } } push(operatorActions, buffer[i]); } @@ -80,21 +81,18 @@ bool converterToPostfixForm(const char buffer[], char result[]) { ++i; } while (!isEmpty(operatorActions)) { - char operations = pop(operatorActions, &errorCode); + char symbol[2] = { '\0' }; + returnOperation(operatorActions, symbol, &errorCode, &queue); if (errorCode != 0) { return false; } - char symbol[2] = { '\0' }; - symbol[0] = operations; - if (operations != '(') { - enqueue(&queue, symbol); - } } size_t j = 0; while (!isEmptyQueue(queue)) { char queueElements[100] = { '\0' }; dequeue(&queue, &errorCode, queueElements); if (errorCode != 0) { + clear(&queue); return false; } size_t sizeQueueElements = strlen(queueElements); @@ -113,21 +111,21 @@ bool converterToPostfixForm(const char buffer[], char result[]) { } if (operatorActions != NULL) { if (!isEmpty(operatorActions)) { - deleteStack(operatorActions); + deleteStack(&operatorActions); return false; } - deleteStack(operatorActions); + deleteStack(&operatorActions); } return true; } bool firstTest() { - char buffer[12] = { '(', '1', ' ', '+', ' ', '2', ')', ' ', '*', ' ', '2', '\0' }; + char buffer[] = "(1 + 2) * 2"; char arrayOutput[100] = { '\0' }; if (!converterToPostfixForm(buffer, arrayOutput)) { return false; } - char bufferNew[10] = { '1', ' ', '2', ' ', '+', ' ', '2', ' ', '*', '\0' }; + char bufferNew[] = "1 2 + 2 *"; size_t sizeArrayOutput = strlen(arrayOutput); for (int i = 0; i < sizeArrayOutput - 1; ++i) { @@ -139,12 +137,12 @@ bool firstTest() { } bool secondTest() { - char buffer[18] = { '(', '1', ' ', '+', ' ', '2', ')', ' ', '*', ' ', '(', '1', ' ', '+', ' ', '2', ')', '\0' }; + char buffer[] = "(1 + 2) * (1 + 2)"; char arrayOutput[100] = { '\0' }; if (!converterToPostfixForm(buffer, arrayOutput)) { return false; } - char bufferNew[14] = { '1', ' ', '2', ' ', '+', ' ', '1', ' ', '2', ' ', '+', ' ', '*', '\0' }; + char bufferNew[] = "1 2 + 1 2 + *"; size_t sizeArrayOutput = strlen(arrayOutput); for (int i = 0; i < sizeArrayOutput - 1; ++i) { @@ -162,6 +160,7 @@ int main() { printf(" \n"); } else { printf(" ...\n"); + return -1; } printf(" \n"); diff --git a/sortStation/sortStation/stack.c b/sortStation/sortStation/stack.c index a7613f4..af14f23 100644 --- a/sortStation/sortStation/stack.c +++ b/sortStation/sortStation/stack.c @@ -49,12 +49,12 @@ bool isEmpty(Stack* stack) { return stack->head == NULL; } -void deleteStack(Stack* stack) { - while (!isEmpty(stack)) { +void deleteStack(Stack** stack) { + while (!isEmpty(*stack)) { int errorCode = 0; - pop(stack, &errorCode); + pop(*stack, &errorCode); } - stack = NULL; + *stack = NULL; } Stack* createStack(void) { diff --git a/sortStation/sortStation/stack.h b/sortStation/sortStation/stack.h index 280a991..3073254 100644 --- a/sortStation/sortStation/stack.h +++ b/sortStation/sortStation/stack.h @@ -14,11 +14,12 @@ char pop(Stack* stack, int* errorCode); bool isEmpty(Stack* stack); // -void deleteStack(Stack* stack); +void deleteStack(Stack** stack); // Stack* createStack(void); // char top(Stack* stack); + #endif \ No newline at end of file From efc7226aa0cd8bc7c25e03f8c27f550b4dd4d2b5 Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 23 Dec 2022 17:22:52 +0300 Subject: [PATCH 10/10] =?UTF-8?q?=D0=A0=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sortStation/sortStation/stack.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sortStation/sortStation/stack.c b/sortStation/sortStation/stack.c index af14f23..59c7af5 100644 --- a/sortStation/sortStation/stack.c +++ b/sortStation/sortStation/stack.c @@ -58,9 +58,7 @@ void deleteStack(Stack** stack) { } Stack* createStack(void) { - Stack* stack = malloc(sizeof(Stack)); - stack->head = NULL; - return stack; + return calloc(1, sizeof(Stack)); } char top(Stack* stack) {