From 1a83386b8b8d3005f1011850f7794cb55cbdf78a Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 15 Oct 2021 21:09:51 +0500 Subject: [PATCH 01/32] creating functions for working with the stack and testing them --- Stack/Stack.sln | 31 ++++++ Stack/Stack/Main.c | 10 ++ Stack/Stack/Stack.c | 44 +++++++++ Stack/Stack/Stack.h | 15 +++ Stack/Stack/Stack.vcxproj | 153 ++++++++++++++++++++++++++++++ Stack/Stack/Stack.vcxproj.filters | 36 +++++++ Stack/Stack/StackTest.c | 36 +++++++ Stack/Stack/StackTest.h | 8 ++ 8 files changed, 333 insertions(+) create mode 100644 Stack/Stack.sln create mode 100644 Stack/Stack/Main.c create mode 100644 Stack/Stack/Stack.c create mode 100644 Stack/Stack/Stack.h create mode 100644 Stack/Stack/Stack.vcxproj create mode 100644 Stack/Stack/Stack.vcxproj.filters create mode 100644 Stack/Stack/StackTest.c create mode 100644 Stack/Stack/StackTest.h diff --git a/Stack/Stack.sln b/Stack/Stack.sln new file mode 100644 index 0000000..ce2c4f2 --- /dev/null +++ b/Stack/Stack.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}") = "Stack", "Stack\Stack.vcxproj", "{A4F19B27-54C9-4841-98B0-728EDCD283D2}" +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 + {A4F19B27-54C9-4841-98B0-728EDCD283D2}.Debug|x64.ActiveCfg = Debug|x64 + {A4F19B27-54C9-4841-98B0-728EDCD283D2}.Debug|x64.Build.0 = Debug|x64 + {A4F19B27-54C9-4841-98B0-728EDCD283D2}.Debug|x86.ActiveCfg = Debug|Win32 + {A4F19B27-54C9-4841-98B0-728EDCD283D2}.Debug|x86.Build.0 = Debug|Win32 + {A4F19B27-54C9-4841-98B0-728EDCD283D2}.Release|x64.ActiveCfg = Release|x64 + {A4F19B27-54C9-4841-98B0-728EDCD283D2}.Release|x64.Build.0 = Release|x64 + {A4F19B27-54C9-4841-98B0-728EDCD283D2}.Release|x86.ActiveCfg = Release|Win32 + {A4F19B27-54C9-4841-98B0-728EDCD283D2}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5B7E38AF-1E89-49D4-95EB-B55DB0F7ADDF} + EndGlobalSection +EndGlobal diff --git a/Stack/Stack/Main.c b/Stack/Stack/Main.c new file mode 100644 index 0000000..9c67d17 --- /dev/null +++ b/Stack/Stack/Main.c @@ -0,0 +1,10 @@ +#include +#include "StackTest.h" + +int main() +{ + if (!pushTest() || !popTest() || !deleteStackTest()) + { + return -1; + } +} \ No newline at end of file diff --git a/Stack/Stack/Stack.c b/Stack/Stack/Stack.c new file mode 100644 index 0000000..83a54ae --- /dev/null +++ b/Stack/Stack/Stack.c @@ -0,0 +1,44 @@ +#include +#include +#include + +typedef struct Stack +{ + int value; + struct Stack* next; +}Stack; + +bool isEmpty(Stack* head) +{ + return head == NULL; +} + +void push(Stack** head, int element) +{ + Stack* newStack = (Stack*)calloc(1, sizeof(Stack)); + if (newStack == NULL) + { + return; + } + newStack->value = element; + newStack->next = *head; + *head = newStack; +} + +int pop(Stack** head) +{ + int element = ((*head)->value); + Stack* temporary = *head; + Stack* help = (*head) -> next; + free(temporary); + *head = help; + return element; +} + +void deleteStack(Stack** head) +{ + while (!isEmpty(*head)) + { + pop(head); + } +} diff --git a/Stack/Stack/Stack.h b/Stack/Stack/Stack.h new file mode 100644 index 0000000..662f63a --- /dev/null +++ b/Stack/Stack/Stack.h @@ -0,0 +1,15 @@ +#pragma once + +typedef struct Stack +{ + int value; + struct Stack* next; +}Stack; + +bool isEmpty(Stack* head); + +void push(Stack** head, int element); + +int pop(Stack** head); + +void deleteStack(Stack** head); \ No newline at end of file diff --git a/Stack/Stack/Stack.vcxproj b/Stack/Stack/Stack.vcxproj new file mode 100644 index 0000000..6ced32d --- /dev/null +++ b/Stack/Stack/Stack.vcxproj @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {a4f19b27-54c9-4841-98b0-728edcd283d2} + Stack + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Stack/Stack/Stack.vcxproj.filters b/Stack/Stack/Stack.vcxproj.filters new file mode 100644 index 0000000..4428432 --- /dev/null +++ b/Stack/Stack/Stack.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/Stack/Stack/StackTest.c b/Stack/Stack/StackTest.c new file mode 100644 index 0000000..1d2af0d --- /dev/null +++ b/Stack/Stack/StackTest.c @@ -0,0 +1,36 @@ +#include "StackTest.h" +#include "Stack.h" +#include + +bool pushTest() +{ + Stack* p = NULL; + push(&p, 12); + int firstResult = p->value; + push(&p, 128); + int secondResult = p->value; + return firstResult == 12 && secondResult == 128; +} + +bool popTest() +{ + Stack* p = NULL; + push(&p, 12); + push(&p, 128); + push(&p, 147); + int firstPopResult = pop(&p); + int firstUpperElement = p -> value; + int secondPopResult = pop(&p); + int secondUpperElement = p->value; + return firstPopResult == 147 && firstUpperElement == 128 && secondPopResult == 128 && secondUpperElement == 12; +} + +bool deleteStackTest() +{ + Stack* p = NULL; + push(&p, 12); + push(&p, 128); + push(&p, 147); + deleteStack(&p); + return p == NULL; +} \ No newline at end of file diff --git a/Stack/Stack/StackTest.h b/Stack/Stack/StackTest.h new file mode 100644 index 0000000..3715ed1 --- /dev/null +++ b/Stack/Stack/StackTest.h @@ -0,0 +1,8 @@ +#pragma once +#include + +bool pushTest(); + +bool popTest(); + +bool deleteStackTest(); \ No newline at end of file From 2549f2f4c184e87538f017792b85ca21f565a09b Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 16 Oct 2021 00:30:59 +0500 Subject: [PATCH 02/32] fixed bugs --- Stack/Stack/Stack.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Stack/Stack/Stack.c b/Stack/Stack/Stack.c index 83a54ae..9147894 100644 --- a/Stack/Stack/Stack.c +++ b/Stack/Stack/Stack.c @@ -1,12 +1,7 @@ #include #include #include - -typedef struct Stack -{ - int value; - struct Stack* next; -}Stack; +#include "Stack.h" bool isEmpty(Stack* head) { From 8d6727ea2be14c0768b8a988360e5e199d56d0ea Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 16 Oct 2021 02:26:23 +0500 Subject: [PATCH 03/32] fixed bugs --- Stack/Stack/Stack.h | 5 ++++ Stack/Stack/Stack.vcxproj.filters | 6 ++--- Stack/Stack/StackTest.c | 38 +++++++++++++++---------------- Stack/Stack/StackTest.h | 3 +++ 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Stack/Stack/Stack.h b/Stack/Stack/Stack.h index 662f63a..0cdaa86 100644 --- a/Stack/Stack/Stack.h +++ b/Stack/Stack/Stack.h @@ -1,15 +1,20 @@ #pragma once +// Structure for implementing a stack consisting of a value and a pointer to the next element typedef struct Stack { int value; struct Stack* next; }Stack; +// Function that checks the stack for emptiness bool isEmpty(Stack* head); +// Function for adding an element to the top of the stack void push(Stack** head, int element); +// Function to remove an element from the top of the stack that returns the value of that element int pop(Stack** head); +// Function for deleting all stack elements void deleteStack(Stack** head); \ No newline at end of file diff --git a/Stack/Stack/Stack.vcxproj.filters b/Stack/Stack/Stack.vcxproj.filters index 4428432..ff73484 100644 --- a/Stack/Stack/Stack.vcxproj.filters +++ b/Stack/Stack/Stack.vcxproj.filters @@ -15,15 +15,15 @@ - - Исходные файлы - Исходные файлы Исходные файлы + + Исходные файлы + diff --git a/Stack/Stack/StackTest.c b/Stack/Stack/StackTest.c index 1d2af0d..25e812d 100644 --- a/Stack/Stack/StackTest.c +++ b/Stack/Stack/StackTest.c @@ -4,33 +4,33 @@ bool pushTest() { - Stack* p = NULL; - push(&p, 12); - int firstResult = p->value; - push(&p, 128); - int secondResult = p->value; + Stack* head = NULL; + push(&head, 12); + int firstResult = head->value; + push(&head, 128); + int secondResult = head->value; return firstResult == 12 && secondResult == 128; } bool popTest() { - Stack* p = NULL; - push(&p, 12); - push(&p, 128); - push(&p, 147); - int firstPopResult = pop(&p); - int firstUpperElement = p -> value; - int secondPopResult = pop(&p); - int secondUpperElement = p->value; + Stack* head = NULL; + push(&head, 12); + push(&head, 128); + push(&head, 147); + int firstPopResult = pop(&head); + int firstUpperElement = head -> value; + int secondPopResult = pop(&head); + int secondUpperElement = head->value; return firstPopResult == 147 && firstUpperElement == 128 && secondPopResult == 128 && secondUpperElement == 12; } bool deleteStackTest() { - Stack* p = NULL; - push(&p, 12); - push(&p, 128); - push(&p, 147); - deleteStack(&p); - return p == NULL; + Stack* head = NULL; + push(&head, 12); + push(&head, 128); + push(&head, 147); + deleteStack(&head); + return head == NULL; } \ No newline at end of file diff --git a/Stack/Stack/StackTest.h b/Stack/Stack/StackTest.h index 3715ed1..ca939fc 100644 --- a/Stack/Stack/StackTest.h +++ b/Stack/Stack/StackTest.h @@ -1,8 +1,11 @@ #pragma once #include +// Function to check the function that adds an element to the top of the stack bool pushTest(); +// Function to check the function that removes from the top of the stack bool popTest(); +// Function for checking a function that removes all stack elements bool deleteStackTest(); \ No newline at end of file From f43380d7b949a6b4e12dc28197af441e4f751210 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 16 Oct 2021 04:58:24 +0500 Subject: [PATCH 04/32] start --- Postfixform/Postfixform.sln | 31 ++++ Postfixform/Postfixform/Postfix.c | 23 +++ Postfixform/Postfixform/Postfix.h | 1 + Postfixform/Postfixform/Postfixform.vcxproj | 165 ++++++++++++++++++ .../Postfixform/Postfixform.vcxproj.filters | 27 +++ 5 files changed, 247 insertions(+) create mode 100644 Postfixform/Postfixform.sln create mode 100644 Postfixform/Postfixform/Postfix.c create mode 100644 Postfixform/Postfixform/Postfix.h create mode 100644 Postfixform/Postfixform/Postfixform.vcxproj create mode 100644 Postfixform/Postfixform/Postfixform.vcxproj.filters diff --git a/Postfixform/Postfixform.sln b/Postfixform/Postfixform.sln new file mode 100644 index 0000000..96a9e8b --- /dev/null +++ b/Postfixform/Postfixform.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}") = "Postfixform", "Postfixform\Postfixform.vcxproj", "{15009E36-9D86-441E-A9EA-947AAC734F19}" +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 + {15009E36-9D86-441E-A9EA-947AAC734F19}.Debug|x64.ActiveCfg = Debug|x64 + {15009E36-9D86-441E-A9EA-947AAC734F19}.Debug|x64.Build.0 = Debug|x64 + {15009E36-9D86-441E-A9EA-947AAC734F19}.Debug|x86.ActiveCfg = Debug|Win32 + {15009E36-9D86-441E-A9EA-947AAC734F19}.Debug|x86.Build.0 = Debug|Win32 + {15009E36-9D86-441E-A9EA-947AAC734F19}.Release|x64.ActiveCfg = Release|x64 + {15009E36-9D86-441E-A9EA-947AAC734F19}.Release|x64.Build.0 = Release|x64 + {15009E36-9D86-441E-A9EA-947AAC734F19}.Release|x86.ActiveCfg = Release|Win32 + {15009E36-9D86-441E-A9EA-947AAC734F19}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C330BC54-81A6-4E6B-9775-51E396ACC586} + EndGlobalSection +EndGlobal diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c new file mode 100644 index 0000000..7730cd2 --- /dev/null +++ b/Postfixform/Postfixform/Postfix.c @@ -0,0 +1,23 @@ +#include +#include +#include + +int asdasd(char* postfixEntry) +{ + int counter = 0; + while (postfixEntry[counter] != '\0') + { + if (postfixEntry[counter] >= '0' && postfixEntry[counter] <= '9') + { + push() + } + } +} + +int main() +{ + char postfixEntry[250] = '\0'; + printf("enter the expression in postfix form"); + gets(postfixEntry); + asdasd(postfixEntry); +} \ No newline at end of file diff --git a/Postfixform/Postfixform/Postfix.h b/Postfixform/Postfixform/Postfix.h new file mode 100644 index 0000000..7b9637e --- /dev/null +++ b/Postfixform/Postfixform/Postfix.h @@ -0,0 +1 @@ +#pragma once \ No newline at end of file diff --git a/Postfixform/Postfixform/Postfixform.vcxproj b/Postfixform/Postfixform/Postfixform.vcxproj new file mode 100644 index 0000000..c06d2f7 --- /dev/null +++ b/Postfixform/Postfixform/Postfixform.vcxproj @@ -0,0 +1,165 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + 16.0 + Win32Proj + {15009e36-9d86-441e-a9ea-947aac734f19} + Postfixform + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + false + + + + + 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/Postfixform/Postfixform/Postfixform.vcxproj.filters b/Postfixform/Postfixform/Postfixform.vcxproj.filters new file mode 100644 index 0000000..3862470 --- /dev/null +++ b/Postfixform/Postfixform/Postfixform.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {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 d2884fcead8a76b6598c0cb32d17ffa9da3f599e Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 16 Oct 2021 16:41:00 +0500 Subject: [PATCH 05/32] start --- Postfixform/Postfixform/Postfix.c | 37 +++++++++++++++++-- Postfixform/Postfixform/Postfix.h | 1 - Postfixform/Postfixform/Postfixform.vcxproj | 3 -- .../Postfixform/Postfixform.vcxproj.filters | 5 --- 4 files changed, 34 insertions(+), 12 deletions(-) delete mode 100644 Postfixform/Postfixform/Postfix.h diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index 7730cd2..ddd37a7 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -1,23 +1,54 @@ #include #include #include +#include "Stack.h" int asdasd(char* postfixEntry) { + Stack* head = NULL; int counter = 0; + int firstNumber = 0; + int secondNumber = 0; while (postfixEntry[counter] != '\0') { if (postfixEntry[counter] >= '0' && postfixEntry[counter] <= '9') { - push() + push(&head, postfixEntry[counter]); + } + if (postfixEntry[counter] = '-') + { + secondNumber = pop(&head); + firstNumber = pop(&head); + push(&head, firstNumber - secondNumber); + } + if (postfixEntry[counter] = '+') + { + secondNumber = pop(&head); + firstNumber = pop(&head); + push(&head, firstNumber + secondNumber); + } + if (postfixEntry[counter] = '*') + { + secondNumber = pop(&head); + firstNumber = pop(&head); + push(&head, firstNumber * secondNumber); + } + if (postfixEntry[counter] = '/') + { + secondNumber = pop(&head); + firstNumber = pop(&head); + push(&head, firstNumber / secondNumber); } } + int answer = head -> value; + return answer; } int main() { - char postfixEntry[250] = '\0'; + char postfixEntry[250] = {'\0'}; printf("enter the expression in postfix form"); gets(postfixEntry); - asdasd(postfixEntry); + int answer = asdasd(postfixEntry); + printf("%d", answer); } \ No newline at end of file diff --git a/Postfixform/Postfixform/Postfix.h b/Postfixform/Postfixform/Postfix.h deleted file mode 100644 index 7b9637e..0000000 --- a/Postfixform/Postfixform/Postfix.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once \ No newline at end of file diff --git a/Postfixform/Postfixform/Postfixform.vcxproj b/Postfixform/Postfixform/Postfixform.vcxproj index c06d2f7..b24b7a2 100644 --- a/Postfixform/Postfixform/Postfixform.vcxproj +++ b/Postfixform/Postfixform/Postfixform.vcxproj @@ -18,9 +18,6 @@ x64 - - - diff --git a/Postfixform/Postfixform/Postfixform.vcxproj.filters b/Postfixform/Postfixform/Postfixform.vcxproj.filters index 3862470..dd04df6 100644 --- a/Postfixform/Postfixform/Postfixform.vcxproj.filters +++ b/Postfixform/Postfixform/Postfixform.vcxproj.filters @@ -14,11 +14,6 @@ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - Файлы заголовков - - Исходные файлы From e7e22d69f8093efe9dd9c3a1143fc7d5413c616e Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 16 Oct 2021 16:46:47 +0500 Subject: [PATCH 06/32] add function --- Stack/Stack/Stack.c | 9 ++++----- Stack/Stack/Stack.h | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Stack/Stack/Stack.c b/Stack/Stack/Stack.c index 9147894..32eb4d1 100644 --- a/Stack/Stack/Stack.c +++ b/Stack/Stack/Stack.c @@ -1,7 +1,6 @@ +#include "Stack.h" #include -#include #include -#include "Stack.h" bool isEmpty(Stack* head) { @@ -15,14 +14,14 @@ void push(Stack** head, int element) { return; } - newStack->value = element; - newStack->next = *head; + newStack -> value = element; + newStack -> next = *head; *head = newStack; } int pop(Stack** head) { - int element = ((*head)->value); + int element = (*head) -> value; Stack* temporary = *head; Stack* help = (*head) -> next; free(temporary); diff --git a/Stack/Stack/Stack.h b/Stack/Stack/Stack.h index 0cdaa86..b58f850 100644 --- a/Stack/Stack/Stack.h +++ b/Stack/Stack/Stack.h @@ -1,5 +1,5 @@ #pragma once - +#include // Structure for implementing a stack consisting of a value and a pointer to the next element typedef struct Stack { @@ -7,7 +7,7 @@ typedef struct Stack struct Stack* next; }Stack; -// Function that checks the stack for emptiness +// Function for test empty stack bool isEmpty(Stack* head); // Function for adding an element to the top of the stack From 2f9e2a0327ca32d6427f571b8a993e85b81c0ed0 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 16 Oct 2021 17:02:46 +0500 Subject: [PATCH 07/32] fixed bugs --- Stack/Stack/Main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stack/Stack/Main.c b/Stack/Stack/Main.c index 9c67d17..6eff2a4 100644 --- a/Stack/Stack/Main.c +++ b/Stack/Stack/Main.c @@ -1,5 +1,5 @@ -#include #include "StackTest.h" +#include int main() { From 9a061fadcd23974d8898a50abacb3f08dde9c41f Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 16 Oct 2021 20:50:45 +0500 Subject: [PATCH 08/32] writing all functions, adding comments --- Postfixform/Postfixform/Postfix.c | 91 ++++++++++++------- Postfixform/Postfixform/Postfix.h | 4 + Postfixform/Postfixform/PostfixFormTest.c | 15 +++ Postfixform/Postfixform/PostfixFormTest.h | 5 + Postfixform/Postfixform/Postfixform.vcxproj | 9 ++ .../Postfixform/Postfixform.vcxproj.filters | 23 +++++ Postfixform/Postfixform/Stack.c | 38 ++++++++ Postfixform/Postfixform/Stack.h | 21 +++++ Postfixform/Postfixform/StackTest.c | 36 ++++++++ Postfixform/Postfixform/StackTest.h | 11 +++ 10 files changed, 222 insertions(+), 31 deletions(-) create mode 100644 Postfixform/Postfixform/Postfix.h create mode 100644 Postfixform/Postfixform/PostfixFormTest.c create mode 100644 Postfixform/Postfixform/PostfixFormTest.h create mode 100644 Postfixform/Postfixform/Stack.c create mode 100644 Postfixform/Postfixform/Stack.h create mode 100644 Postfixform/Postfixform/StackTest.c create mode 100644 Postfixform/Postfixform/StackTest.h diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index ddd37a7..2ea1646 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -1,54 +1,83 @@ +#include "Stack.h" +#include "StackTest.h" +#include "postfixFormTest.h" #include -#include #include -#include "Stack.h" -int asdasd(char* postfixEntry) +int convertFromThePostfixForm(char* postfixEntry) { Stack* head = NULL; int counter = 0; int firstNumber = 0; int secondNumber = 0; + while (postfixEntry[counter] != '\0') { - if (postfixEntry[counter] >= '0' && postfixEntry[counter] <= '9') - { - push(&head, postfixEntry[counter]); - } - if (postfixEntry[counter] = '-') - { - secondNumber = pop(&head); - firstNumber = pop(&head); - push(&head, firstNumber - secondNumber); - } - if (postfixEntry[counter] = '+') + if (postfixEntry[counter] >= (int)('0') && postfixEntry[counter] <= (int)('9')) { - secondNumber = pop(&head); - firstNumber = pop(&head); - push(&head, firstNumber + secondNumber); + push(&head, (postfixEntry[counter] - '0')); } - if (postfixEntry[counter] = '*') + else { - secondNumber = pop(&head); - firstNumber = pop(&head); - push(&head, firstNumber * secondNumber); - } - if (postfixEntry[counter] = '/') - { - secondNumber = pop(&head); - firstNumber = pop(&head); - push(&head, firstNumber / secondNumber); + if(!isEmpty(head)) + { + secondNumber = pop(&head); + } + else + { + return INT_MAX; + } + if (!isEmpty(head)) + { + firstNumber = pop(&head); + } + else + { + return INT_MAX; + } + if (postfixEntry[counter] == '-') + { + push(&head, (firstNumber - secondNumber)); + } + else if (postfixEntry[counter] == '+') + { + push(&head, firstNumber + secondNumber); + } + else if (postfixEntry[counter] == '*') + { + push(&head, firstNumber * secondNumber); + } + else if (postfixEntry[counter] == '/') + { + push(&head, firstNumber / secondNumber); + } + else + { + return INT_MAX; + } } + counter++; } - int answer = head -> value; + int answer = pop(&head); + deleteStack(&head); return answer; } int main() { + if (!pushTest() || !popTest() || !deleteStackTest() || !postfixFormTest()) + { + printf("Test failed"); + return -1; + } char postfixEntry[250] = {'\0'}; - printf("enter the expression in postfix form"); - gets(postfixEntry); - int answer = asdasd(postfixEntry); + printf("enter the expression in postfix form\n"); + scanf_s("%s", postfixEntry, (unsigned)_countof(postfixEntry)); + int answer = convertFromThePostfixForm(postfixEntry); + if (answer == INT_MAX) + { + printf("Incorrect input"); + return 0; + } printf("%d", answer); } \ No newline at end of file diff --git a/Postfixform/Postfixform/Postfix.h b/Postfixform/Postfixform/Postfix.h new file mode 100644 index 0000000..ae8bce8 --- /dev/null +++ b/Postfixform/Postfixform/Postfix.h @@ -0,0 +1,4 @@ +#pragma once + +// Function that translates an expression from a postfix form +int convertFromThePostfixForm(char* postfixEntry); \ No newline at end of file diff --git a/Postfixform/Postfixform/PostfixFormTest.c b/Postfixform/Postfixform/PostfixFormTest.c new file mode 100644 index 0000000..e5157d8 --- /dev/null +++ b/Postfixform/Postfixform/PostfixFormTest.c @@ -0,0 +1,15 @@ +#include "PostfixFormTest.h" +#include "Postfix.h" +#include + +bool postfixFormTest() +{ + char firstPostfixEntry[250] = "32-45*+29-*"; + char secondPostfixEntry[250] = "26---"; + char thirdPostfixEntry[250] = "34*23-+72-*"; + char fourthPostfixEntry[250] = "34=+12"; + return convertFromThePostfixForm(firstPostfixEntry) == -147 + && convertFromThePostfixForm(secondPostfixEntry) == INT_MAX + && convertFromThePostfixForm(thirdPostfixEntry) == 55 + && convertFromThePostfixForm(fourthPostfixEntry) == INT_MAX; +} \ No newline at end of file diff --git a/Postfixform/Postfixform/PostfixFormTest.h b/Postfixform/Postfixform/PostfixFormTest.h new file mode 100644 index 0000000..4a25766 --- /dev/null +++ b/Postfixform/Postfixform/PostfixFormTest.h @@ -0,0 +1,5 @@ +#pragma once +#include + +// Function for testing a function that translates an expression from a postfix form +bool postfixFormTest(); \ No newline at end of file diff --git a/Postfixform/Postfixform/Postfixform.vcxproj b/Postfixform/Postfixform/Postfixform.vcxproj index b24b7a2..9a06fc7 100644 --- a/Postfixform/Postfixform/Postfixform.vcxproj +++ b/Postfixform/Postfixform/Postfixform.vcxproj @@ -20,6 +20,15 @@ + + + + + + + + + 16.0 diff --git a/Postfixform/Postfixform/Postfixform.vcxproj.filters b/Postfixform/Postfixform/Postfixform.vcxproj.filters index dd04df6..61a7e73 100644 --- a/Postfixform/Postfixform/Postfixform.vcxproj.filters +++ b/Postfixform/Postfixform/Postfixform.vcxproj.filters @@ -18,5 +18,28 @@ Исходные файлы + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + + + Файлы заголовков + + + Файлы заголовков + + + Файлы заголовков + + + Файлы заголовков + \ No newline at end of file diff --git a/Postfixform/Postfixform/Stack.c b/Postfixform/Postfixform/Stack.c new file mode 100644 index 0000000..5519cb4 --- /dev/null +++ b/Postfixform/Postfixform/Stack.c @@ -0,0 +1,38 @@ +#include "Stack.h" +#include +#include + +bool isEmpty(Stack* head) +{ + return head == NULL; +} + +void push(Stack** head, int element) +{ + Stack* newStack = (Stack*)calloc(1, sizeof(Stack)); + if (newStack == NULL) + { + return; + } + newStack->value = element; + newStack->next = *head; + *head = newStack; +} + +int pop(Stack** head) +{ + int element = (*head) -> value; + Stack* temporary = *head; + Stack* help = (*head) -> next; + free(temporary); + *head = help; + return element; +} + +void deleteStack(Stack** head) +{ + while (!isEmpty(*head)) + { + pop(head); + } +} diff --git a/Postfixform/Postfixform/Stack.h b/Postfixform/Postfixform/Stack.h new file mode 100644 index 0000000..d14a2a9 --- /dev/null +++ b/Postfixform/Postfixform/Stack.h @@ -0,0 +1,21 @@ +#pragma once +#include + +// Structure for implementing a stack consisting of a value and a pointer to the next element +typedef struct Stack +{ + int value; + struct Stack* next; +}Stack; + +// Function that checks the stack for emptiness +bool isEmpty(Stack* head); + +// Function for adding an element to the top of the stack +void push(Stack** head, int element); + +// Function to remove an element from the top of the stack that returns the value of that element +int pop(Stack** head); + +// Function for deleting all stack elements +void deleteStack(Stack** head); \ No newline at end of file diff --git a/Postfixform/Postfixform/StackTest.c b/Postfixform/Postfixform/StackTest.c new file mode 100644 index 0000000..25e812d --- /dev/null +++ b/Postfixform/Postfixform/StackTest.c @@ -0,0 +1,36 @@ +#include "StackTest.h" +#include "Stack.h" +#include + +bool pushTest() +{ + Stack* head = NULL; + push(&head, 12); + int firstResult = head->value; + push(&head, 128); + int secondResult = head->value; + return firstResult == 12 && secondResult == 128; +} + +bool popTest() +{ + Stack* head = NULL; + push(&head, 12); + push(&head, 128); + push(&head, 147); + int firstPopResult = pop(&head); + int firstUpperElement = head -> value; + int secondPopResult = pop(&head); + int secondUpperElement = head->value; + return firstPopResult == 147 && firstUpperElement == 128 && secondPopResult == 128 && secondUpperElement == 12; +} + +bool deleteStackTest() +{ + Stack* head = NULL; + push(&head, 12); + push(&head, 128); + push(&head, 147); + deleteStack(&head); + return head == NULL; +} \ No newline at end of file diff --git a/Postfixform/Postfixform/StackTest.h b/Postfixform/Postfixform/StackTest.h new file mode 100644 index 0000000..ca939fc --- /dev/null +++ b/Postfixform/Postfixform/StackTest.h @@ -0,0 +1,11 @@ +#pragma once +#include + +// Function to check the function that adds an element to the top of the stack +bool pushTest(); + +// Function to check the function that removes from the top of the stack +bool popTest(); + +// Function for checking a function that removes all stack elements +bool deleteStackTest(); \ No newline at end of file From a67b184ec1f3f38ce049fe7f3be1a87f1d5e0c2e Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 17 Oct 2021 01:03:04 +0500 Subject: [PATCH 09/32] fixed bugs --- Postfixform/Postfixform/Postfix.c | 4 +- Postfixform/Postfixform/Postfixform.vcxproj | 8 ++-- .../Postfixform/Postfixform.vcxproj.filters | 14 +++---- Postfixform/Postfixform/Stack.c | 38 ------------------- Postfixform/Postfixform/Stack.h | 21 ---------- Postfixform/Postfixform/StackTest.c | 36 ------------------ Postfixform/Postfixform/StackTest.h | 11 ------ 7 files changed, 13 insertions(+), 119 deletions(-) delete mode 100644 Postfixform/Postfixform/Stack.c delete mode 100644 Postfixform/Postfixform/Stack.h delete mode 100644 Postfixform/Postfixform/StackTest.c delete mode 100644 Postfixform/Postfixform/StackTest.h diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index 2ea1646..3a44ba3 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -1,5 +1,5 @@ -#include "Stack.h" -#include "StackTest.h" +#include "../../Stack/Stack/Stack.h" +#include "../../Stack/Stack/StackTest.h" #include "postfixFormTest.h" #include #include diff --git a/Postfixform/Postfixform/Postfixform.vcxproj b/Postfixform/Postfixform/Postfixform.vcxproj index 9a06fc7..653f842 100644 --- a/Postfixform/Postfixform/Postfixform.vcxproj +++ b/Postfixform/Postfixform/Postfixform.vcxproj @@ -19,15 +19,15 @@ + + - - + + - - diff --git a/Postfixform/Postfixform/Postfixform.vcxproj.filters b/Postfixform/Postfixform/Postfixform.vcxproj.filters index 61a7e73..531055b 100644 --- a/Postfixform/Postfixform/Postfixform.vcxproj.filters +++ b/Postfixform/Postfixform/Postfixform.vcxproj.filters @@ -18,27 +18,27 @@ Исходные файлы - + Исходные файлы - + Исходные файлы - + Исходные файлы - + Файлы заголовков - + Файлы заголовков - + Файлы заголовков - + Файлы заголовков diff --git a/Postfixform/Postfixform/Stack.c b/Postfixform/Postfixform/Stack.c deleted file mode 100644 index 5519cb4..0000000 --- a/Postfixform/Postfixform/Stack.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "Stack.h" -#include -#include - -bool isEmpty(Stack* head) -{ - return head == NULL; -} - -void push(Stack** head, int element) -{ - Stack* newStack = (Stack*)calloc(1, sizeof(Stack)); - if (newStack == NULL) - { - return; - } - newStack->value = element; - newStack->next = *head; - *head = newStack; -} - -int pop(Stack** head) -{ - int element = (*head) -> value; - Stack* temporary = *head; - Stack* help = (*head) -> next; - free(temporary); - *head = help; - return element; -} - -void deleteStack(Stack** head) -{ - while (!isEmpty(*head)) - { - pop(head); - } -} diff --git a/Postfixform/Postfixform/Stack.h b/Postfixform/Postfixform/Stack.h deleted file mode 100644 index d14a2a9..0000000 --- a/Postfixform/Postfixform/Stack.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -#include - -// Structure for implementing a stack consisting of a value and a pointer to the next element -typedef struct Stack -{ - int value; - struct Stack* next; -}Stack; - -// Function that checks the stack for emptiness -bool isEmpty(Stack* head); - -// Function for adding an element to the top of the stack -void push(Stack** head, int element); - -// Function to remove an element from the top of the stack that returns the value of that element -int pop(Stack** head); - -// Function for deleting all stack elements -void deleteStack(Stack** head); \ No newline at end of file diff --git a/Postfixform/Postfixform/StackTest.c b/Postfixform/Postfixform/StackTest.c deleted file mode 100644 index 25e812d..0000000 --- a/Postfixform/Postfixform/StackTest.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "StackTest.h" -#include "Stack.h" -#include - -bool pushTest() -{ - Stack* head = NULL; - push(&head, 12); - int firstResult = head->value; - push(&head, 128); - int secondResult = head->value; - return firstResult == 12 && secondResult == 128; -} - -bool popTest() -{ - Stack* head = NULL; - push(&head, 12); - push(&head, 128); - push(&head, 147); - int firstPopResult = pop(&head); - int firstUpperElement = head -> value; - int secondPopResult = pop(&head); - int secondUpperElement = head->value; - return firstPopResult == 147 && firstUpperElement == 128 && secondPopResult == 128 && secondUpperElement == 12; -} - -bool deleteStackTest() -{ - Stack* head = NULL; - push(&head, 12); - push(&head, 128); - push(&head, 147); - deleteStack(&head); - return head == NULL; -} \ No newline at end of file diff --git a/Postfixform/Postfixform/StackTest.h b/Postfixform/Postfixform/StackTest.h deleted file mode 100644 index ca939fc..0000000 --- a/Postfixform/Postfixform/StackTest.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#include - -// Function to check the function that adds an element to the top of the stack -bool pushTest(); - -// Function to check the function that removes from the top of the stack -bool popTest(); - -// Function for checking a function that removes all stack elements -bool deleteStackTest(); \ No newline at end of file From 015e87ef14d7237253535cb277fd258c301fb5ba Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 17 Oct 2021 01:30:28 +0500 Subject: [PATCH 10/32] fixed bugs --- Stack/Stack/Stack.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Stack/Stack/Stack.h b/Stack/Stack/Stack.h index b58f850..fb3b361 100644 --- a/Stack/Stack/Stack.h +++ b/Stack/Stack/Stack.h @@ -1,5 +1,6 @@ #pragma once #include + // Structure for implementing a stack consisting of a value and a pointer to the next element typedef struct Stack { From 5c8f0cf33ca5adfa2859fb9340250d825ed26d4b Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 22 Oct 2021 17:06:42 +0500 Subject: [PATCH 11/32] fixed bugs --- Postfixform/Postfixform/Postfix.c | 105 ++++++++++++---------- Postfixform/Postfixform/Postfix.h | 3 +- Postfixform/Postfixform/PostfixFormTest.c | 12 ++- 3 files changed, 69 insertions(+), 51 deletions(-) diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index 3a44ba3..80b345d 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -3,62 +3,74 @@ #include "postfixFormTest.h" #include #include +#include -int convertFromThePostfixForm(char* postfixEntry) +int convertFromThePostfixForm(char* postfixEntry, bool* check) { Stack* head = NULL; - int counter = 0; - int firstNumber = 0; - int secondNumber = 0; - + int counter = 0; while (postfixEntry[counter] != '\0') { - if (postfixEntry[counter] >= (int)('0') && postfixEntry[counter] <= (int)('9')) + if (postfixEntry[counter] >= '0' && postfixEntry[counter] <= '9') { push(&head, (postfixEntry[counter] - '0')); + counter++; + continue; + } + else if (postfixEntry[counter] == ' ') + { + counter++; + continue; + } + int secondNumber = 0; + int firstNumber = 0; + if (!isEmpty(head)) + { + secondNumber = pop(&head); + } + else + { + *check = false; + return 0; + } + if (!isEmpty(head)) + { + firstNumber = pop(&head); } else { - if(!isEmpty(head)) - { - secondNumber = pop(&head); - } - else - { - return INT_MAX; - } - if (!isEmpty(head)) - { - firstNumber = pop(&head); - } - else - { - return INT_MAX; - } - if (postfixEntry[counter] == '-') - { - push(&head, (firstNumber - secondNumber)); - } - else if (postfixEntry[counter] == '+') - { - push(&head, firstNumber + secondNumber); - } - else if (postfixEntry[counter] == '*') - { - push(&head, firstNumber * secondNumber); - } - else if (postfixEntry[counter] == '/') - { - push(&head, firstNumber / secondNumber); - } - else - { - return INT_MAX; - } + *check = false; + return 0; } + if (postfixEntry[counter] == '-') + { + push(&head, (firstNumber - secondNumber)); + } + else if (postfixEntry[counter] == '+') + { + push(&head, firstNumber + secondNumber); + } + else if (postfixEntry[counter] == '*') + { + push(&head, firstNumber * secondNumber); + } + else if (postfixEntry[counter] == '/') + { + push(&head, firstNumber / secondNumber); + } + else + { + *check = false; + return 0; + } counter++; } - int answer = pop(&head); + const int answer = pop(&head); + if (!isEmpty(head)) + { + *check = false; + return 0; + } deleteStack(&head); return answer; } @@ -72,9 +84,10 @@ int main() } char postfixEntry[250] = {'\0'}; printf("enter the expression in postfix form\n"); - scanf_s("%s", postfixEntry, (unsigned)_countof(postfixEntry)); - int answer = convertFromThePostfixForm(postfixEntry); - if (answer == INT_MAX) + scanf_s("%[^\n]s", postfixEntry, (unsigned)_countof(postfixEntry)); + bool check = true; + const int answer = convertFromThePostfixForm(postfixEntry, &check); + if (!check) { printf("Incorrect input"); return 0; diff --git a/Postfixform/Postfixform/Postfix.h b/Postfixform/Postfixform/Postfix.h index ae8bce8..8bb23dd 100644 --- a/Postfixform/Postfixform/Postfix.h +++ b/Postfixform/Postfixform/Postfix.h @@ -1,4 +1,5 @@ #pragma once +#include // Function that translates an expression from a postfix form -int convertFromThePostfixForm(char* postfixEntry); \ No newline at end of file +int convertFromThePostfixForm(char* postfixEntry, bool *check); \ No newline at end of file diff --git a/Postfixform/Postfixform/PostfixFormTest.c b/Postfixform/Postfixform/PostfixFormTest.c index e5157d8..92a4fd3 100644 --- a/Postfixform/Postfixform/PostfixFormTest.c +++ b/Postfixform/Postfixform/PostfixFormTest.c @@ -8,8 +8,12 @@ bool postfixFormTest() char secondPostfixEntry[250] = "26---"; char thirdPostfixEntry[250] = "34*23-+72-*"; char fourthPostfixEntry[250] = "34=+12"; - return convertFromThePostfixForm(firstPostfixEntry) == -147 - && convertFromThePostfixForm(secondPostfixEntry) == INT_MAX - && convertFromThePostfixForm(thirdPostfixEntry) == 55 - && convertFromThePostfixForm(fourthPostfixEntry) == INT_MAX; + bool firstCheck = true; + bool secondCheck = true; + bool thirdCheck = true; + bool fourthcheck = true; + return convertFromThePostfixForm(firstPostfixEntry, &firstCheck) == -147 && firstCheck + && convertFromThePostfixForm(secondPostfixEntry, &secondCheck) == 0 && !secondCheck + && convertFromThePostfixForm(thirdPostfixEntry, &thirdCheck) == 55 && thirdCheck + && convertFromThePostfixForm(fourthPostfixEntry, &fourthcheck) == 0 && !fourthcheck; } \ No newline at end of file From d85663e4bf9d8cc0dc3d5a494f81a3453b09191f Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 22 Oct 2021 17:22:48 +0500 Subject: [PATCH 12/32] fixed bugs --- Stack/Stack/Stack.c | 23 ++++++++++++++--------- Stack/Stack/Stack.h | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Stack/Stack/Stack.c b/Stack/Stack/Stack.c index 32eb4d1..d904d0e 100644 --- a/Stack/Stack/Stack.c +++ b/Stack/Stack/Stack.c @@ -14,19 +14,24 @@ void push(Stack** head, int element) { return; } - newStack -> value = element; - newStack -> next = *head; + newStack->value = element; + newStack->next = *head; *head = newStack; } -int pop(Stack** head) +int pop(Stack** head, errno_t err) { - int element = (*head) -> value; - Stack* temporary = *head; - Stack* help = (*head) -> next; - free(temporary); - *head = help; - return element; + if (*head != NULL) + { + int element = (*head)->value; + Stack* temporary = *head; + *head = (*head)->next; + free(temporary); + return element; + } + errno_t err = 1; + error(err); + return 0; } void deleteStack(Stack** head) diff --git a/Stack/Stack/Stack.h b/Stack/Stack/Stack.h index fb3b361..1906590 100644 --- a/Stack/Stack/Stack.h +++ b/Stack/Stack/Stack.h @@ -15,7 +15,7 @@ bool isEmpty(Stack* head); void push(Stack** head, int element); // Function to remove an element from the top of the stack that returns the value of that element -int pop(Stack** head); +int pop(Stack** head, errno_t err); // Function for deleting all stack elements void deleteStack(Stack** head); \ No newline at end of file From 6a502c15fc6b0141b88e3a1b976c5d2be5af67d5 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 22 Oct 2021 17:42:27 +0500 Subject: [PATCH 13/32] fixed bugs --- Stack/Stack/Stack.c | 8 ++++---- Stack/Stack/Stack.h | 2 +- Stack/Stack/StackTest.c | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Stack/Stack/Stack.c b/Stack/Stack/Stack.c index d904d0e..595797c 100644 --- a/Stack/Stack/Stack.c +++ b/Stack/Stack/Stack.c @@ -19,7 +19,7 @@ void push(Stack** head, int element) *head = newStack; } -int pop(Stack** head, errno_t err) +int pop(Stack** head, bool* err) { if (*head != NULL) { @@ -29,15 +29,15 @@ int pop(Stack** head, errno_t err) free(temporary); return element; } - errno_t err = 1; - error(err); + *err = false; return 0; } void deleteStack(Stack** head) { + bool err = true; while (!isEmpty(*head)) { - pop(head); + pop(head, &err); } } diff --git a/Stack/Stack/Stack.h b/Stack/Stack/Stack.h index 1906590..3c551c7 100644 --- a/Stack/Stack/Stack.h +++ b/Stack/Stack/Stack.h @@ -15,7 +15,7 @@ bool isEmpty(Stack* head); void push(Stack** head, int element); // Function to remove an element from the top of the stack that returns the value of that element -int pop(Stack** head, errno_t err); +int pop(Stack** head, bool* err); // Function for deleting all stack elements void deleteStack(Stack** head); \ No newline at end of file diff --git a/Stack/Stack/StackTest.c b/Stack/Stack/StackTest.c index 25e812d..bef4be9 100644 --- a/Stack/Stack/StackTest.c +++ b/Stack/Stack/StackTest.c @@ -14,13 +14,14 @@ bool pushTest() bool popTest() { + bool err = true; Stack* head = NULL; push(&head, 12); push(&head, 128); push(&head, 147); - int firstPopResult = pop(&head); + int firstPopResult = pop(&head, &err); int firstUpperElement = head -> value; - int secondPopResult = pop(&head); + int secondPopResult = pop(&head, &err); int secondUpperElement = head->value; return firstPopResult == 147 && firstUpperElement == 128 && secondPopResult == 128 && secondUpperElement == 12; } From 58913fa81a7a12fa527895d172d6408d6bd1025c Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 22 Oct 2021 18:46:54 +0500 Subject: [PATCH 14/32] fixed bugs --- Postfixform/Postfixform/Main.c | 27 ++++++++++++ Postfixform/Postfixform/Postfix.c | 44 ++++--------------- Postfixform/Postfixform/Postfix.h | 2 +- Postfixform/Postfixform/PostfixFormTest.c | 10 ++--- Postfixform/Postfixform/Postfixform.vcxproj | 1 + .../Postfixform/Postfixform.vcxproj.filters | 3 ++ 6 files changed, 46 insertions(+), 41 deletions(-) create mode 100644 Postfixform/Postfixform/Main.c diff --git a/Postfixform/Postfixform/Main.c b/Postfixform/Postfixform/Main.c new file mode 100644 index 0000000..1fe0f91 --- /dev/null +++ b/Postfixform/Postfixform/Main.c @@ -0,0 +1,27 @@ +#include "../../Stack/Stack/Stack.h" +#include "../../Stack/Stack/StackTest.h" +#include "Postfix.h" +#include "postfixFormTest.h" +#include +#include +#include + +int main() +{ + if (!pushTest() || !popTest() || !deleteStackTest() || !postfixFormTest()) + { + printf("Test failed"); + return -1; + } + char postfixEntry[250] = { '\0' }; + printf("enter the expression in postfix form\n"); + scanf_s("%[^\n]s", postfixEntry, (unsigned)_countof(postfixEntry)); + bool check = true; + const int answer = countTheExpression(postfixEntry, &check); + if (!check) + { + printf("Incorrect input"); + return 0; + } + printf("%d", answer); +} \ No newline at end of file diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index 80b345d..c3d3283 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -1,12 +1,12 @@ #include "../../Stack/Stack/Stack.h" #include "../../Stack/Stack/StackTest.h" -#include "postfixFormTest.h" -#include +#include "Postfix.h" #include #include -int convertFromThePostfixForm(char* postfixEntry, bool* check) +int countTheExpression(char* postfixEntry, bool* check) { + bool copy = *check; Stack* head = NULL; int counter = 0; while (postfixEntry[counter] != '\0') @@ -24,23 +24,17 @@ int convertFromThePostfixForm(char* postfixEntry, bool* check) } int secondNumber = 0; int firstNumber = 0; - if (!isEmpty(head)) - { - secondNumber = pop(&head); - } - else + secondNumber = pop(&head, ©); + if (copy == false) { *check = false; return 0; } - if (!isEmpty(head)) - { - firstNumber = pop(&head); - } - else + firstNumber = pop(&head, ©); + if (copy == false) { *check = false; - return 0; + return 0; } if (postfixEntry[counter] == '-') { @@ -65,7 +59,7 @@ int convertFromThePostfixForm(char* postfixEntry, bool* check) } counter++; } - const int answer = pop(&head); + const int answer = pop(&head, ©); if (!isEmpty(head)) { *check = false; @@ -73,24 +67,4 @@ int convertFromThePostfixForm(char* postfixEntry, bool* check) } deleteStack(&head); return answer; -} - -int main() -{ - if (!pushTest() || !popTest() || !deleteStackTest() || !postfixFormTest()) - { - printf("Test failed"); - return -1; - } - char postfixEntry[250] = {'\0'}; - printf("enter the expression in postfix form\n"); - scanf_s("%[^\n]s", postfixEntry, (unsigned)_countof(postfixEntry)); - bool check = true; - const int answer = convertFromThePostfixForm(postfixEntry, &check); - if (!check) - { - printf("Incorrect input"); - return 0; - } - printf("%d", answer); } \ No newline at end of file diff --git a/Postfixform/Postfixform/Postfix.h b/Postfixform/Postfixform/Postfix.h index 8bb23dd..2c8f123 100644 --- a/Postfixform/Postfixform/Postfix.h +++ b/Postfixform/Postfixform/Postfix.h @@ -2,4 +2,4 @@ #include // Function that translates an expression from a postfix form -int convertFromThePostfixForm(char* postfixEntry, bool *check); \ No newline at end of file +int countTheExpression(char* postfixEntry, bool *check); \ No newline at end of file diff --git a/Postfixform/Postfixform/PostfixFormTest.c b/Postfixform/Postfixform/PostfixFormTest.c index 92a4fd3..1091dea 100644 --- a/Postfixform/Postfixform/PostfixFormTest.c +++ b/Postfixform/Postfixform/PostfixFormTest.c @@ -6,14 +6,14 @@ bool postfixFormTest() { char firstPostfixEntry[250] = "32-45*+29-*"; char secondPostfixEntry[250] = "26---"; - char thirdPostfixEntry[250] = "34*23-+72-*"; + char thirdPostfixEntry[250] = "9 6 - 1 2 + *"; char fourthPostfixEntry[250] = "34=+12"; bool firstCheck = true; bool secondCheck = true; bool thirdCheck = true; bool fourthcheck = true; - return convertFromThePostfixForm(firstPostfixEntry, &firstCheck) == -147 && firstCheck - && convertFromThePostfixForm(secondPostfixEntry, &secondCheck) == 0 && !secondCheck - && convertFromThePostfixForm(thirdPostfixEntry, &thirdCheck) == 55 && thirdCheck - && convertFromThePostfixForm(fourthPostfixEntry, &fourthcheck) == 0 && !fourthcheck; + return countTheExpression(firstPostfixEntry, &firstCheck) == -147 && firstCheck + && countTheExpression(secondPostfixEntry, &secondCheck) == 0 && !secondCheck + && countTheExpression(thirdPostfixEntry, &thirdCheck) == 9 && thirdCheck + && countTheExpression(fourthPostfixEntry, &fourthcheck) == 0 && !fourthcheck; } \ No newline at end of file diff --git a/Postfixform/Postfixform/Postfixform.vcxproj b/Postfixform/Postfixform/Postfixform.vcxproj index 653f842..95ff921 100644 --- a/Postfixform/Postfixform/Postfixform.vcxproj +++ b/Postfixform/Postfixform/Postfixform.vcxproj @@ -21,6 +21,7 @@ + diff --git a/Postfixform/Postfixform/Postfixform.vcxproj.filters b/Postfixform/Postfixform/Postfixform.vcxproj.filters index 531055b..75eba28 100644 --- a/Postfixform/Postfixform/Postfixform.vcxproj.filters +++ b/Postfixform/Postfixform/Postfixform.vcxproj.filters @@ -27,6 +27,9 @@ Исходные файлы + + Исходные файлы + From e4c55b48a2878a9d7ceeb1a79c93cea72d669ecb Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Fri, 22 Oct 2021 18:53:11 +0500 Subject: [PATCH 15/32] tweaked the code --- Postfixform/Postfixform/Postfix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index c3d3283..841e726 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -25,13 +25,13 @@ int countTheExpression(char* postfixEntry, bool* check) int secondNumber = 0; int firstNumber = 0; secondNumber = pop(&head, ©); - if (copy == false) + if (!copy) { *check = false; return 0; } firstNumber = pop(&head, ©); - if (copy == false) + if (!copy) { *check = false; return 0; From e0ec8d8472dda994aac0ebabfbfb5d23114f28de Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 23 Oct 2021 01:41:38 +0500 Subject: [PATCH 16/32] fixed bugs --- Stack/Stack/StackTest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stack/Stack/StackTest.c b/Stack/Stack/StackTest.c index bef4be9..31fc09a 100644 --- a/Stack/Stack/StackTest.c +++ b/Stack/Stack/StackTest.c @@ -20,7 +20,7 @@ bool popTest() push(&head, 128); push(&head, 147); int firstPopResult = pop(&head, &err); - int firstUpperElement = head -> value; + int firstUpperElement = head->value; int secondPopResult = pop(&head, &err); int secondUpperElement = head->value; return firstPopResult == 147 && firstUpperElement == 128 && secondPopResult == 128 && secondUpperElement == 12; From c7141c5d7ca468d3bf0ab0f29557e0227850e664 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 23 Oct 2021 18:17:32 +0500 Subject: [PATCH 17/32] fixed bugs --- Postfixform/Postfixform/Main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Postfixform/Postfixform/Main.c b/Postfixform/Postfixform/Main.c index 1fe0f91..43d11f4 100644 --- a/Postfixform/Postfixform/Main.c +++ b/Postfixform/Postfixform/Main.c @@ -15,7 +15,7 @@ int main() } char postfixEntry[250] = { '\0' }; printf("enter the expression in postfix form\n"); - scanf_s("%[^\n]s", postfixEntry, (unsigned)_countof(postfixEntry)); + scanf_s("%[^\n]s", postfixEntry, (unsigned)sizeof(postfixEntry)); bool check = true; const int answer = countTheExpression(postfixEntry, &check); if (!check) From 7c6d74e7bd07e558979a6b294dd0b2c57e86c4b4 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 23 Oct 2021 23:50:01 +0500 Subject: [PATCH 18/32] fixed bugs --- Stack/Stack/Stack.c | 12 ++++++------ Stack/Stack/Stack.h | 6 +++--- Stack/Stack/StackTest.c | 5 ++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Stack/Stack/Stack.c b/Stack/Stack/Stack.c index 595797c..0923463 100644 --- a/Stack/Stack/Stack.c +++ b/Stack/Stack/Stack.c @@ -1,6 +1,6 @@ #include "Stack.h" -#include #include +#include bool isEmpty(Stack* head) { @@ -19,25 +19,25 @@ void push(Stack** head, int element) *head = newStack; } -int pop(Stack** head, bool* err) +int pop(Stack** head) { + errno = 0; if (*head != NULL) { - int element = (*head)->value; + const int element = (*head)->value; Stack* temporary = *head; *head = (*head)->next; free(temporary); return element; } - *err = false; + errno = 1; return 0; } void deleteStack(Stack** head) { - bool err = true; while (!isEmpty(*head)) { - pop(head, &err); + pop(head); } } diff --git a/Stack/Stack/Stack.h b/Stack/Stack/Stack.h index 3c551c7..a945b1a 100644 --- a/Stack/Stack/Stack.h +++ b/Stack/Stack/Stack.h @@ -6,16 +6,16 @@ typedef struct Stack { int value; struct Stack* next; -}Stack; +} Stack; -// Function for test empty stack +// Function for testing if stack is empty bool isEmpty(Stack* head); // Function for adding an element to the top of the stack void push(Stack** head, int element); // Function to remove an element from the top of the stack that returns the value of that element -int pop(Stack** head, bool* err); +int pop(Stack** head); // Function for deleting all stack elements void deleteStack(Stack** head); \ No newline at end of file diff --git a/Stack/Stack/StackTest.c b/Stack/Stack/StackTest.c index 31fc09a..c93d5c0 100644 --- a/Stack/Stack/StackTest.c +++ b/Stack/Stack/StackTest.c @@ -14,14 +14,13 @@ bool pushTest() bool popTest() { - bool err = true; Stack* head = NULL; push(&head, 12); push(&head, 128); push(&head, 147); - int firstPopResult = pop(&head, &err); + int firstPopResult = pop(&head); int firstUpperElement = head->value; - int secondPopResult = pop(&head, &err); + int secondPopResult = pop(&head); int secondUpperElement = head->value; return firstPopResult == 147 && firstUpperElement == 128 && secondPopResult == 128 && secondUpperElement == 12; } From cad09143c29f1420d62c4760357cccaa0411e85e Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 23 Oct 2021 23:50:35 +0500 Subject: [PATCH 19/32] fixed bugs --- Postfixform/Postfixform/Main.c | 23 +++++++---- Postfixform/Postfixform/Postfix.c | 30 +++++++-------- Postfixform/Postfixform/Postfix.h | 5 +-- Postfixform/Postfixform/PostfixFormTest.c | 38 ++++++++++++------- Postfixform/Postfixform/PostfixFormTest.h | 2 +- Postfixform/Postfixform/Postfixform.vcxproj | 4 +- .../Postfixform/Postfixform.vcxproj.filters | 6 --- 7 files changed, 57 insertions(+), 51 deletions(-) diff --git a/Postfixform/Postfixform/Main.c b/Postfixform/Postfixform/Main.c index 43d11f4..459e3d4 100644 --- a/Postfixform/Postfixform/Main.c +++ b/Postfixform/Postfixform/Main.c @@ -1,14 +1,12 @@ #include "../../Stack/Stack/Stack.h" -#include "../../Stack/Stack/StackTest.h" #include "Postfix.h" #include "postfixFormTest.h" #include -#include #include int main() { - if (!pushTest() || !popTest() || !deleteStackTest() || !postfixFormTest()) + if (!areTestPassingPostfixForm()) { printf("Test failed"); return -1; @@ -16,12 +14,21 @@ int main() char postfixEntry[250] = { '\0' }; printf("enter the expression in postfix form\n"); scanf_s("%[^\n]s", postfixEntry, (unsigned)sizeof(postfixEntry)); - bool check = true; - const int answer = countTheExpression(postfixEntry, &check); - if (!check) + const int answer = countTheExpression(postfixEntry); + if (errno == 1) { - printf("Incorrect input"); - return 0; + printf("Stack is empty"); + return -1; + } + if (errno == 2) + { + printf("invalid character in the expression entry"); + return -1; + } + if (errno == 3) + { + printf("Incorrect input of an expression in postfix form"); + return -1; } printf("%d", answer); } \ No newline at end of file diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index 841e726..0361d03 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -1,19 +1,16 @@ #include "../../Stack/Stack/Stack.h" -#include "../../Stack/Stack/StackTest.h" #include "Postfix.h" #include -#include -int countTheExpression(char* postfixEntry, bool* check) +int countTheExpression(char* postfixEntry) { - bool copy = *check; Stack* head = NULL; int counter = 0; while (postfixEntry[counter] != '\0') { if (postfixEntry[counter] >= '0' && postfixEntry[counter] <= '9') { - push(&head, (postfixEntry[counter] - '0')); + push(&head, postfixEntry[counter] - '0'); counter++; continue; } @@ -22,18 +19,14 @@ int countTheExpression(char* postfixEntry, bool* check) counter++; continue; } - int secondNumber = 0; - int firstNumber = 0; - secondNumber = pop(&head, ©); - if (!copy) + int secondNumber = pop(&head); + if (errno == 1) { - *check = false; return 0; } - firstNumber = pop(&head, ©); - if (!copy) + int firstNumber = pop(&head); + if (errno == 1) { - *check = false; return 0; } if (postfixEntry[counter] == '-') @@ -54,15 +47,20 @@ int countTheExpression(char* postfixEntry, bool* check) } else { - *check = false; + deleteStack(&head); + errno = 2; return 0; } counter++; } - const int answer = pop(&head, ©); + const int answer = pop(&head); + if (errno == 1) + { + return 0; + } if (!isEmpty(head)) { - *check = false; + errno = 3; return 0; } deleteStack(&head); diff --git a/Postfixform/Postfixform/Postfix.h b/Postfixform/Postfixform/Postfix.h index 2c8f123..c369497 100644 --- a/Postfixform/Postfixform/Postfix.h +++ b/Postfixform/Postfixform/Postfix.h @@ -1,5 +1,4 @@ #pragma once -#include -// Function that translates an expression from a postfix form -int countTheExpression(char* postfixEntry, bool *check); \ No newline at end of file +// Function that translates an expression from a postfix form to an infix form +int countTheExpression(char* postfixEntry); \ No newline at end of file diff --git a/Postfixform/Postfixform/PostfixFormTest.c b/Postfixform/Postfixform/PostfixFormTest.c index 1091dea..8b8654f 100644 --- a/Postfixform/Postfixform/PostfixFormTest.c +++ b/Postfixform/Postfixform/PostfixFormTest.c @@ -1,19 +1,29 @@ #include "PostfixFormTest.h" #include "Postfix.h" -#include -bool postfixFormTest() +bool areTestPassingPostfixForm() { - char firstPostfixEntry[250] = "32-45*+29-*"; - char secondPostfixEntry[250] = "26---"; - char thirdPostfixEntry[250] = "9 6 - 1 2 + *"; - char fourthPostfixEntry[250] = "34=+12"; - bool firstCheck = true; - bool secondCheck = true; - bool thirdCheck = true; - bool fourthcheck = true; - return countTheExpression(firstPostfixEntry, &firstCheck) == -147 && firstCheck - && countTheExpression(secondPostfixEntry, &secondCheck) == 0 && !secondCheck - && countTheExpression(thirdPostfixEntry, &thirdCheck) == 9 && thirdCheck - && countTheExpression(fourthPostfixEntry, &fourthcheck) == 0 && !fourthcheck; + char firstCorrectPostfixEntry[250] = "3 2 - 4 5 * + 2 9 - *"; + char secondCorrectPostfixEntry[250] = "2 3 - 4 5 * +"; + char thirdCorrectPostfixEntry[250] = "9 6 - 1 2 + *"; + char fourthCorrectPostfixEntry[250] = "9 6 - 3 4 * + 5 6 - +"; + char fifthCorrectPostfixEntry[250] = "9 6 - 3 -"; + + char firstIncorrectPostfixEntry[250] = "--35 a-"; + char secondIncorrectPostfixEntry[250] = "456 26"; + char thirdIncorrectPostfixEntry[250] = "34 - 345"; + char fourthIncorrectPostfixEntry[250] = "12 - 34 + 4"; + char fifthIncorrectPostfixEntry[250] = "1234 - 12"; + + return countTheExpression(firstCorrectPostfixEntry) == -147 + && countTheExpression(secondCorrectPostfixEntry) == 19 + && countTheExpression(thirdCorrectPostfixEntry) == 9 + && countTheExpression(fourthCorrectPostfixEntry) == 14 + && countTheExpression(fifthCorrectPostfixEntry) == 0 + + && countTheExpression(firstIncorrectPostfixEntry) == 0 + && countTheExpression(secondIncorrectPostfixEntry) == 0 + && countTheExpression(thirdIncorrectPostfixEntry) == 0 + && countTheExpression(fourthIncorrectPostfixEntry) == 0 + && countTheExpression(fifthIncorrectPostfixEntry) == 0; } \ No newline at end of file diff --git a/Postfixform/Postfixform/PostfixFormTest.h b/Postfixform/Postfixform/PostfixFormTest.h index 4a25766..2a977d7 100644 --- a/Postfixform/Postfixform/PostfixFormTest.h +++ b/Postfixform/Postfixform/PostfixFormTest.h @@ -2,4 +2,4 @@ #include // Function for testing a function that translates an expression from a postfix form -bool postfixFormTest(); \ No newline at end of file +bool areTestPassingPostfixForm(); \ No newline at end of file diff --git a/Postfixform/Postfixform/Postfixform.vcxproj b/Postfixform/Postfixform/Postfixform.vcxproj index 95ff921..dffc7d6 100644 --- a/Postfixform/Postfixform/Postfixform.vcxproj +++ b/Postfixform/Postfixform/Postfixform.vcxproj @@ -20,14 +20,12 @@ - - @@ -136,7 +134,7 @@ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true diff --git a/Postfixform/Postfixform/Postfixform.vcxproj.filters b/Postfixform/Postfixform/Postfixform.vcxproj.filters index 75eba28..a524e54 100644 --- a/Postfixform/Postfixform/Postfixform.vcxproj.filters +++ b/Postfixform/Postfixform/Postfixform.vcxproj.filters @@ -24,9 +24,6 @@ Исходные файлы - - Исходные файлы - Исходные файлы @@ -38,9 +35,6 @@ Файлы заголовков - - Файлы заголовков - Файлы заголовков From fe7b4ae1526fbbc86dae421372da408f2de06d91 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 23 Oct 2021 23:58:27 +0500 Subject: [PATCH 20/32] fixed bugs --- Postfixform/Postfixform/Main.c | 2 ++ Postfixform/Postfixform/Postfix.c | 1 + 2 files changed, 3 insertions(+) diff --git a/Postfixform/Postfixform/Main.c b/Postfixform/Postfixform/Main.c index 459e3d4..727b97d 100644 --- a/Postfixform/Postfixform/Main.c +++ b/Postfixform/Postfixform/Main.c @@ -3,6 +3,7 @@ #include "postfixFormTest.h" #include #include +#include int main() { @@ -14,6 +15,7 @@ int main() char postfixEntry[250] = { '\0' }; printf("enter the expression in postfix form\n"); scanf_s("%[^\n]s", postfixEntry, (unsigned)sizeof(postfixEntry)); + errno = 0; const int answer = countTheExpression(postfixEntry); if (errno == 1) { diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index 0361d03..2dc9cbf 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -1,6 +1,7 @@ #include "../../Stack/Stack/Stack.h" #include "Postfix.h" #include +#include int countTheExpression(char* postfixEntry) { From 465c325e57da11a668edfcc5e90fbdbc969bf01c Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 24 Oct 2021 04:33:23 +0500 Subject: [PATCH 21/32] changing the type to float for a problem with a postfix form --- Stack/Stack/Stack.c | 6 +++--- Stack/Stack/Stack.h | 6 +++--- Stack/Stack/StackTest.c | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Stack/Stack/Stack.c b/Stack/Stack/Stack.c index 0923463..041a96e 100644 --- a/Stack/Stack/Stack.c +++ b/Stack/Stack/Stack.c @@ -7,7 +7,7 @@ bool isEmpty(Stack* head) return head == NULL; } -void push(Stack** head, int element) +void push(Stack** head, float element) { Stack* newStack = (Stack*)calloc(1, sizeof(Stack)); if (newStack == NULL) @@ -19,12 +19,12 @@ void push(Stack** head, int element) *head = newStack; } -int pop(Stack** head) +float pop(Stack** head) { errno = 0; if (*head != NULL) { - const int element = (*head)->value; + const float element = (*head)->value; Stack* temporary = *head; *head = (*head)->next; free(temporary); diff --git a/Stack/Stack/Stack.h b/Stack/Stack/Stack.h index a945b1a..b0e7b4c 100644 --- a/Stack/Stack/Stack.h +++ b/Stack/Stack/Stack.h @@ -4,7 +4,7 @@ // Structure for implementing a stack consisting of a value and a pointer to the next element typedef struct Stack { - int value; + float value; struct Stack* next; } Stack; @@ -12,10 +12,10 @@ typedef struct Stack bool isEmpty(Stack* head); // Function for adding an element to the top of the stack -void push(Stack** head, int element); +void push(Stack** head, float element); // Function to remove an element from the top of the stack that returns the value of that element -int pop(Stack** head); +float pop(Stack** head); // Function for deleting all stack elements void deleteStack(Stack** head); \ No newline at end of file diff --git a/Stack/Stack/StackTest.c b/Stack/Stack/StackTest.c index c93d5c0..8174556 100644 --- a/Stack/Stack/StackTest.c +++ b/Stack/Stack/StackTest.c @@ -6,9 +6,9 @@ bool pushTest() { Stack* head = NULL; push(&head, 12); - int firstResult = head->value; + float firstResult = head->value; push(&head, 128); - int secondResult = head->value; + float secondResult = head->value; return firstResult == 12 && secondResult == 128; } @@ -18,10 +18,10 @@ bool popTest() push(&head, 12); push(&head, 128); push(&head, 147); - int firstPopResult = pop(&head); - int firstUpperElement = head->value; - int secondPopResult = pop(&head); - int secondUpperElement = head->value; + float firstPopResult = pop(&head); + float firstUpperElement = head->value; + float secondPopResult = pop(&head); + float secondUpperElement = head->value; return firstPopResult == 147 && firstUpperElement == 128 && secondPopResult == 128 && secondUpperElement == 12; } From ff4b737cc5006c6bfe3c1a40f13267fe8650a82d Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 24 Oct 2021 04:43:10 +0500 Subject: [PATCH 22/32] replacing int with float(for example, for 92/ = 4.5) --- Postfixform/Postfixform/Main.c | 4 ++-- Postfixform/Postfixform/Postfix.c | 10 +++++----- Postfixform/Postfixform/Postfix.h | 2 +- Postfixform/Postfixform/PostfixFormTest.c | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Postfixform/Postfixform/Main.c b/Postfixform/Postfixform/Main.c index 727b97d..2fa5fb4 100644 --- a/Postfixform/Postfixform/Main.c +++ b/Postfixform/Postfixform/Main.c @@ -16,7 +16,7 @@ int main() printf("enter the expression in postfix form\n"); scanf_s("%[^\n]s", postfixEntry, (unsigned)sizeof(postfixEntry)); errno = 0; - const int answer = countTheExpression(postfixEntry); + const float answer = countTheExpression(postfixEntry); if (errno == 1) { printf("Stack is empty"); @@ -32,5 +32,5 @@ int main() printf("Incorrect input of an expression in postfix form"); return -1; } - printf("%d", answer); + printf("%f", answer); } \ No newline at end of file diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index 2dc9cbf..b9c9f41 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -3,7 +3,7 @@ #include #include -int countTheExpression(char* postfixEntry) +float countTheExpression(char* postfixEntry) { Stack* head = NULL; int counter = 0; @@ -11,7 +11,7 @@ int countTheExpression(char* postfixEntry) { if (postfixEntry[counter] >= '0' && postfixEntry[counter] <= '9') { - push(&head, postfixEntry[counter] - '0'); + push(&head, (float)postfixEntry[counter] - '0'); counter++; continue; } @@ -20,12 +20,12 @@ int countTheExpression(char* postfixEntry) counter++; continue; } - int secondNumber = pop(&head); + float secondNumber = pop(&head); if (errno == 1) { return 0; } - int firstNumber = pop(&head); + float firstNumber = pop(&head); if (errno == 1) { return 0; @@ -54,7 +54,7 @@ int countTheExpression(char* postfixEntry) } counter++; } - const int answer = pop(&head); + const float answer = pop(&head); if (errno == 1) { return 0; diff --git a/Postfixform/Postfixform/Postfix.h b/Postfixform/Postfixform/Postfix.h index c369497..2c864dc 100644 --- a/Postfixform/Postfixform/Postfix.h +++ b/Postfixform/Postfixform/Postfix.h @@ -1,4 +1,4 @@ #pragma once // Function that translates an expression from a postfix form to an infix form -int countTheExpression(char* postfixEntry); \ No newline at end of file +float countTheExpression(char* postfixEntry); \ No newline at end of file diff --git a/Postfixform/Postfixform/PostfixFormTest.c b/Postfixform/Postfixform/PostfixFormTest.c index 8b8654f..a3208bd 100644 --- a/Postfixform/Postfixform/PostfixFormTest.c +++ b/Postfixform/Postfixform/PostfixFormTest.c @@ -6,7 +6,7 @@ bool areTestPassingPostfixForm() char firstCorrectPostfixEntry[250] = "3 2 - 4 5 * + 2 9 - *"; char secondCorrectPostfixEntry[250] = "2 3 - 4 5 * +"; char thirdCorrectPostfixEntry[250] = "9 6 - 1 2 + *"; - char fourthCorrectPostfixEntry[250] = "9 6 - 3 4 * + 5 6 - +"; + char fourthCorrectPostfixEntry[250] = "9 6 - 5 2 / +"; char fifthCorrectPostfixEntry[250] = "9 6 - 3 -"; char firstIncorrectPostfixEntry[250] = "--35 a-"; @@ -18,7 +18,7 @@ bool areTestPassingPostfixForm() return countTheExpression(firstCorrectPostfixEntry) == -147 && countTheExpression(secondCorrectPostfixEntry) == 19 && countTheExpression(thirdCorrectPostfixEntry) == 9 - && countTheExpression(fourthCorrectPostfixEntry) == 14 + && countTheExpression(fourthCorrectPostfixEntry) == 5.5 && countTheExpression(fifthCorrectPostfixEntry) == 0 && countTheExpression(firstIncorrectPostfixEntry) == 0 From a759b102af5b54227f4fb900ec5f97493bc68645 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 24 Oct 2021 04:47:35 +0500 Subject: [PATCH 23/32] fixed bugs --- Postfixform/Postfixform/Postfix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Postfixform/Postfixform/Postfix.h b/Postfixform/Postfixform/Postfix.h index 2c864dc..cabf0f3 100644 --- a/Postfixform/Postfixform/Postfix.h +++ b/Postfixform/Postfixform/Postfix.h @@ -1,4 +1,4 @@ #pragma once -// Function that translates an expression from a postfix form to an infix form +// Function for outputting the value of an expression in postfix form float countTheExpression(char* postfixEntry); \ No newline at end of file From 3bd13521b25e1f5a672d7c35f81e41b905de9c2a Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 24 Oct 2021 04:56:18 +0500 Subject: [PATCH 24/32] fixed bugs --- Postfixform/Postfixform/Postfix.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index b9c9f41..5dbae24 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -61,6 +61,7 @@ float countTheExpression(char* postfixEntry) } if (!isEmpty(head)) { + deleteStack(&head); errno = 3; return 0; } From f6d3e25315a84bf4b133ad50d80c941deaee5453 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 24 Oct 2021 05:03:18 +0500 Subject: [PATCH 25/32] fixed bugs --- Postfixform/Postfixform/Postfix.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index 5dbae24..d92a2d7 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -65,6 +65,5 @@ float countTheExpression(char* postfixEntry) errno = 3; return 0; } - deleteStack(&head); return answer; } \ No newline at end of file From e0515c6c7f13f6476b0fe4b0b52591edfd87bbe8 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 24 Oct 2021 05:10:45 +0500 Subject: [PATCH 26/32] fixed comments --- Postfixform/Postfixform/Postfix.h | 2 +- Postfixform/Postfixform/PostfixFormTest.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Postfixform/Postfixform/Postfix.h b/Postfixform/Postfixform/Postfix.h index cabf0f3..f956d90 100644 --- a/Postfixform/Postfixform/Postfix.h +++ b/Postfixform/Postfixform/Postfix.h @@ -1,4 +1,4 @@ #pragma once -// Function for outputting the value of an expression in postfix form +// Function for calculating the value of an expression in postfix form float countTheExpression(char* postfixEntry); \ No newline at end of file diff --git a/Postfixform/Postfixform/PostfixFormTest.h b/Postfixform/Postfixform/PostfixFormTest.h index 2a977d7..9a0a766 100644 --- a/Postfixform/Postfixform/PostfixFormTest.h +++ b/Postfixform/Postfixform/PostfixFormTest.h @@ -1,5 +1,5 @@ #pragma once #include -// Function for testing a function that translates an expression from a postfix form +// Function for testing a function that considers the value of an expression in postfix form bool areTestPassingPostfixForm(); \ No newline at end of file From 18ca3e3dbf054573c9d5bf6455f3edce67674036 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 24 Oct 2021 05:40:38 +0500 Subject: [PATCH 27/32] fixed bugs --- Postfixform/Postfixform/PostfixFormTest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Postfixform/Postfixform/PostfixFormTest.h b/Postfixform/Postfixform/PostfixFormTest.h index 9a0a766..2a977d7 100644 --- a/Postfixform/Postfixform/PostfixFormTest.h +++ b/Postfixform/Postfixform/PostfixFormTest.h @@ -1,5 +1,5 @@ #pragma once #include -// Function for testing a function that considers the value of an expression in postfix form +// Function for testing a function that translates an expression from a postfix form bool areTestPassingPostfixForm(); \ No newline at end of file From c2f8ecfbbc0eb708fc307790d36a406d0fb4bbfa Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Mon, 25 Oct 2021 16:43:06 +0500 Subject: [PATCH 28/32] fixed a bug with the error code --- Stack/Stack/Stack.c | 9 +++++---- Stack/Stack/Stack.h | 2 +- Stack/Stack/StackTest.c | 15 +++++++++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Stack/Stack/Stack.c b/Stack/Stack/Stack.c index 041a96e..6d45f7f 100644 --- a/Stack/Stack/Stack.c +++ b/Stack/Stack/Stack.c @@ -19,9 +19,9 @@ void push(Stack** head, float element) *head = newStack; } -float pop(Stack** head) +float pop(Stack** head, int* error) { - errno = 0; + *error = 0; if (*head != NULL) { const float element = (*head)->value; @@ -30,14 +30,15 @@ float pop(Stack** head) free(temporary); return element; } - errno = 1; + *error = 1; return 0; } void deleteStack(Stack** head) { + int error = 0; while (!isEmpty(*head)) { - pop(head); + pop(head, &error); } } diff --git a/Stack/Stack/Stack.h b/Stack/Stack/Stack.h index b0e7b4c..9555b4e 100644 --- a/Stack/Stack/Stack.h +++ b/Stack/Stack/Stack.h @@ -15,7 +15,7 @@ bool isEmpty(Stack* head); void push(Stack** head, float element); // Function to remove an element from the top of the stack that returns the value of that element -float pop(Stack** head); +float pop(Stack** head, int* error); // Function for deleting all stack elements void deleteStack(Stack** head); \ No newline at end of file diff --git a/Stack/Stack/StackTest.c b/Stack/Stack/StackTest.c index 8174556..1201044 100644 --- a/Stack/Stack/StackTest.c +++ b/Stack/Stack/StackTest.c @@ -9,6 +9,7 @@ bool pushTest() float firstResult = head->value; push(&head, 128); float secondResult = head->value; + deleteStack(&head); return firstResult == 12 && secondResult == 128; } @@ -18,10 +19,20 @@ bool popTest() push(&head, 12); push(&head, 128); push(&head, 147); - float firstPopResult = pop(&head); + int error = 0; + float firstPopResult = pop(&head, &error); + if (error == 1) + { + return false; + } float firstUpperElement = head->value; - float secondPopResult = pop(&head); + float secondPopResult = pop(&head, &error); + if (error == 1) + { + return false; + } float secondUpperElement = head->value; + deleteStack(&head); return firstPopResult == 147 && firstUpperElement == 128 && secondPopResult == 128 && secondUpperElement == 12; } From 7fe0b6b619ac3d034c9cc7857bf94ea88ba7d6df Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Mon, 25 Oct 2021 17:18:08 +0500 Subject: [PATCH 29/32] working with error codes, replacing tests, the case is considered when dividing by 0 --- Postfixform/Postfixform/Main.c | 20 +++++++-------- Postfixform/Postfixform/Postfix.c | 30 ++++++++++++++--------- Postfixform/Postfixform/Postfix.h | 2 +- Postfixform/Postfixform/PostfixFormTest.c | 26 +++++++++++--------- 4 files changed, 43 insertions(+), 35 deletions(-) diff --git a/Postfixform/Postfixform/Main.c b/Postfixform/Postfixform/Main.c index 2fa5fb4..d80a502 100644 --- a/Postfixform/Postfixform/Main.c +++ b/Postfixform/Postfixform/Main.c @@ -1,9 +1,7 @@ #include "../../Stack/Stack/Stack.h" -#include "Postfix.h" -#include "postfixFormTest.h" +#include "Postfix.h" +#include "PostfixFormTest.h" #include -#include -#include int main() { @@ -15,21 +13,21 @@ int main() char postfixEntry[250] = { '\0' }; printf("enter the expression in postfix form\n"); scanf_s("%[^\n]s", postfixEntry, (unsigned)sizeof(postfixEntry)); - errno = 0; - const float answer = countTheExpression(postfixEntry); - if (errno == 1) + int errorCode = 0; + const float answer = countTheExpression(postfixEntry, &errorCode); + if (errorCode == 1) { - printf("Stack is empty"); + printf("Incorrect input of an expression in postfix form"); return -1; } - if (errno == 2) + if (errorCode == 2) { printf("invalid character in the expression entry"); return -1; } - if (errno == 3) + if (errorCode == 3) { - printf("Incorrect input of an expression in postfix form"); + printf("it is impossible to divide by 0"); return -1; } printf("%f", answer); diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index d92a2d7..1746539 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -1,12 +1,12 @@ #include "../../Stack/Stack/Stack.h" #include "Postfix.h" #include -#include -float countTheExpression(char* postfixEntry) +float countTheExpression(char* postfixEntry, int* errorCode) { Stack* head = NULL; int counter = 0; + int error = 0; while (postfixEntry[counter] != '\0') { if (postfixEntry[counter] >= '0' && postfixEntry[counter] <= '9') @@ -20,15 +20,17 @@ float countTheExpression(char* postfixEntry) counter++; continue; } - float secondNumber = pop(&head); - if (errno == 1) + float secondNumber = pop(&head, &error); + if (error == 1) { + *errorCode = error; return 0; } - float firstNumber = pop(&head); - if (errno == 1) + float firstNumber = pop(&head, &error); + if (error == 1) { - return 0; + *errorCode = error; + return 0; } if (postfixEntry[counter] == '-') { @@ -44,25 +46,31 @@ float countTheExpression(char* postfixEntry) } else if (postfixEntry[counter] == '/') { + if (secondNumber == 0) + { + *errorCode = 3; + return 0; + } push(&head, firstNumber / secondNumber); } else { deleteStack(&head); - errno = 2; + *errorCode = 2; return 0; } counter++; } - const float answer = pop(&head); - if (errno == 1) + const float answer = pop(&head, &error); + if (error == 1) { + *errorCode = error; return 0; } if (!isEmpty(head)) { deleteStack(&head); - errno = 3; + *errorCode = 1; return 0; } return answer; diff --git a/Postfixform/Postfixform/Postfix.h b/Postfixform/Postfixform/Postfix.h index f956d90..7a1b364 100644 --- a/Postfixform/Postfixform/Postfix.h +++ b/Postfixform/Postfixform/Postfix.h @@ -1,4 +1,4 @@ #pragma once // Function for calculating the value of an expression in postfix form -float countTheExpression(char* postfixEntry); \ No newline at end of file +float countTheExpression(char* postfixEntry, int* errorCode); \ No newline at end of file diff --git a/Postfixform/Postfixform/PostfixFormTest.c b/Postfixform/Postfixform/PostfixFormTest.c index a3208bd..820d7b5 100644 --- a/Postfixform/Postfixform/PostfixFormTest.c +++ b/Postfixform/Postfixform/PostfixFormTest.c @@ -9,21 +9,23 @@ bool areTestPassingPostfixForm() char fourthCorrectPostfixEntry[250] = "9 6 - 5 2 / +"; char fifthCorrectPostfixEntry[250] = "9 6 - 3 -"; - char firstIncorrectPostfixEntry[250] = "--35 a-"; - char secondIncorrectPostfixEntry[250] = "456 26"; + char firstIncorrectPostfixEntry[250] = "3 5 a"; + char secondIncorrectPostfixEntry[250] = "4 0 /"; char thirdIncorrectPostfixEntry[250] = "34 - 345"; char fourthIncorrectPostfixEntry[250] = "12 - 34 + 4"; char fifthIncorrectPostfixEntry[250] = "1234 - 12"; - return countTheExpression(firstCorrectPostfixEntry) == -147 - && countTheExpression(secondCorrectPostfixEntry) == 19 - && countTheExpression(thirdCorrectPostfixEntry) == 9 - && countTheExpression(fourthCorrectPostfixEntry) == 5.5 - && countTheExpression(fifthCorrectPostfixEntry) == 0 + int errorCode[10] = {0}; + + return countTheExpression(firstCorrectPostfixEntry, &errorCode[0]) == -147 && errorCode[0] == 0 + && countTheExpression(secondCorrectPostfixEntry, &errorCode[1]) == 19 && errorCode[1] == 0 + && countTheExpression(thirdCorrectPostfixEntry, &errorCode[2]) == 9 && errorCode[2] == 0 + && countTheExpression(fourthCorrectPostfixEntry, &errorCode[3]) == 5.5 && errorCode[3] == 0 + && countTheExpression(fifthCorrectPostfixEntry, &errorCode[4]) == 0 && errorCode[4] == 0 - && countTheExpression(firstIncorrectPostfixEntry) == 0 - && countTheExpression(secondIncorrectPostfixEntry) == 0 - && countTheExpression(thirdIncorrectPostfixEntry) == 0 - && countTheExpression(fourthIncorrectPostfixEntry) == 0 - && countTheExpression(fifthIncorrectPostfixEntry) == 0; + && countTheExpression(firstIncorrectPostfixEntry, &errorCode[5]) == 0 && errorCode[5] == 2 + && countTheExpression(secondIncorrectPostfixEntry, &errorCode[6]) == 0 && errorCode[6] == 3 + && countTheExpression(thirdIncorrectPostfixEntry, &errorCode[7]) == 0 && errorCode[7] == 1 + && countTheExpression(fourthIncorrectPostfixEntry, &errorCode[8]) == 0 && errorCode[8] == 1 + && countTheExpression(fifthIncorrectPostfixEntry, &errorCode[9]) == 0 && errorCode[9] == 1; } \ No newline at end of file From 6dfd83e1e61c731dbbe802cf637904d864fdc94c Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Mon, 25 Oct 2021 17:21:35 +0500 Subject: [PATCH 30/32] removed the unnecessary one .h file --- Stack/Stack/Stack.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Stack/Stack/Stack.c b/Stack/Stack/Stack.c index 6d45f7f..d838ed5 100644 --- a/Stack/Stack/Stack.c +++ b/Stack/Stack/Stack.c @@ -1,6 +1,5 @@ #include "Stack.h" #include -#include bool isEmpty(Stack* head) { From 954d78b9f536abedc97e4d78b17da7bd42136fee Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Mon, 25 Oct 2021 18:44:08 +0500 Subject: [PATCH 31/32] adding const --- Postfixform/Postfixform/Postfix.c | 2 +- Postfixform/Postfixform/Postfix.h | 2 +- Postfixform/Postfixform/PostfixFormTest.c | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Postfixform/Postfixform/Postfix.c b/Postfixform/Postfixform/Postfix.c index 1746539..3d2b162 100644 --- a/Postfixform/Postfixform/Postfix.c +++ b/Postfixform/Postfixform/Postfix.c @@ -2,7 +2,7 @@ #include "Postfix.h" #include -float countTheExpression(char* postfixEntry, int* errorCode) +float countTheExpression(const char* postfixEntry, int* errorCode) { Stack* head = NULL; int counter = 0; diff --git a/Postfixform/Postfixform/Postfix.h b/Postfixform/Postfixform/Postfix.h index 7a1b364..2523b3c 100644 --- a/Postfixform/Postfixform/Postfix.h +++ b/Postfixform/Postfixform/Postfix.h @@ -1,4 +1,4 @@ #pragma once // Function for calculating the value of an expression in postfix form -float countTheExpression(char* postfixEntry, int* errorCode); \ No newline at end of file +float countTheExpression(const char* postfixEntry, int* errorCode); \ No newline at end of file diff --git a/Postfixform/Postfixform/PostfixFormTest.c b/Postfixform/Postfixform/PostfixFormTest.c index 820d7b5..343078b 100644 --- a/Postfixform/Postfixform/PostfixFormTest.c +++ b/Postfixform/Postfixform/PostfixFormTest.c @@ -3,17 +3,17 @@ bool areTestPassingPostfixForm() { - char firstCorrectPostfixEntry[250] = "3 2 - 4 5 * + 2 9 - *"; - char secondCorrectPostfixEntry[250] = "2 3 - 4 5 * +"; - char thirdCorrectPostfixEntry[250] = "9 6 - 1 2 + *"; - char fourthCorrectPostfixEntry[250] = "9 6 - 5 2 / +"; - char fifthCorrectPostfixEntry[250] = "9 6 - 3 -"; + const char firstCorrectPostfixEntry[250] = "3 2 - 4 5 * + 2 9 - *"; + const char secondCorrectPostfixEntry[250] = "2 3 - 4 5 * +"; + const char thirdCorrectPostfixEntry[250] = "9 6 - 1 2 + *"; + const char fourthCorrectPostfixEntry[250] = "9 6 - 5 2 / +"; + const char fifthCorrectPostfixEntry[250] = "9 6 - 3 -"; - char firstIncorrectPostfixEntry[250] = "3 5 a"; - char secondIncorrectPostfixEntry[250] = "4 0 /"; - char thirdIncorrectPostfixEntry[250] = "34 - 345"; - char fourthIncorrectPostfixEntry[250] = "12 - 34 + 4"; - char fifthIncorrectPostfixEntry[250] = "1234 - 12"; + const char firstIncorrectPostfixEntry[250] = "3 5 a"; + const char secondIncorrectPostfixEntry[250] = "4 0 /"; + const char thirdIncorrectPostfixEntry[250] = "34 - 345"; + const char fourthIncorrectPostfixEntry[250] = "12 - 34 + 4"; + const char fifthIncorrectPostfixEntry[250] = "1234 - 12"; int errorCode[10] = {0}; From 98a42e2a2370424c3303c487655c239a5d9a5f3a Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Mon, 25 Oct 2021 18:45:56 +0500 Subject: [PATCH 32/32] adding const --- Stack/Stack/StackTest.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Stack/Stack/StackTest.c b/Stack/Stack/StackTest.c index 1201044..96d6c80 100644 --- a/Stack/Stack/StackTest.c +++ b/Stack/Stack/StackTest.c @@ -6,9 +6,9 @@ bool pushTest() { Stack* head = NULL; push(&head, 12); - float firstResult = head->value; + const float firstResult = head->value; push(&head, 128); - float secondResult = head->value; + const float secondResult = head->value; deleteStack(&head); return firstResult == 12 && secondResult == 128; } @@ -20,18 +20,18 @@ bool popTest() push(&head, 128); push(&head, 147); int error = 0; - float firstPopResult = pop(&head, &error); + const float firstPopResult = pop(&head, &error); if (error == 1) { return false; } - float firstUpperElement = head->value; - float secondPopResult = pop(&head, &error); + const float firstUpperElement = head->value; + const float secondPopResult = pop(&head, &error); if (error == 1) { return false; } - float secondUpperElement = head->value; + const float secondUpperElement = head->value; deleteStack(&head); return firstPopResult == 147 && firstUpperElement == 128 && secondPopResult == 128 && secondUpperElement == 12; }