From e43c97e4d667a2006aa384b35f1c79dc467e90d8 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Wed, 15 Oct 2025 17:30:50 +0300 Subject: [PATCH 1/7] Stack 1.0 --- 5/stack.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 5/stack.h | 18 ++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 5/stack.c create mode 100644 5/stack.h diff --git a/5/stack.c b/5/stack.c new file mode 100644 index 0000000..eaae60e --- /dev/null +++ b/5/stack.c @@ -0,0 +1,46 @@ +#include "stack.h" + + +void init(Stack* stack) { + (*stack).top = NULL; + (*stack).size = 0; +} + +void push(Stack* stack, char value) { + Node* new_node = malloc(sizeof(Node)); + + (*new_node).value = value; + (*new_node).next = (*stack).top; + + (*stack).top = new_node; + (*stack).size++; +} + + + +Node* pop(Stack* stack) { + if ((*stack).top == NULL) { + return NULL; + } + + Node* out = (*stack).top; + (*stack).top = (*out).next; + + (*stack).size--; + + return out; +} + +void printStack(Stack* stack) { + if ((*stack).size == 0) { + printf("\n"); + return; + } + Node* current = (*stack).top; + do { + printf("%c ", (*current).value); + current = (*current).next; + } + while (current != NULL); + printf("\n"); +} diff --git a/5/stack.h b/5/stack.h new file mode 100644 index 0000000..b2d5857 --- /dev/null +++ b/5/stack.h @@ -0,0 +1,18 @@ +#include +#include + +typedef struct Node { + char value; + struct Node* next; +} Node; + +typedef struct Stack { + Node* top; + int size; +} Stack; + + +void init(Stack* stack); +void push(Stack* stack, char value); +Node* pop(Stack* stack); +void printStack(Stack* stack); From 9cb289df99bb112fa7895915227fb128fcca14b0 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Wed, 15 Oct 2025 17:39:25 +0300 Subject: [PATCH 2/7] shunting yard --- 5/shuntingYard.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 5/shuntingYard.c diff --git a/5/shuntingYard.c b/5/shuntingYard.c new file mode 100644 index 0000000..b24e856 --- /dev/null +++ b/5/shuntingYard.c @@ -0,0 +1,88 @@ +#include "stack.h" + +int getPriority(char cur); + + +void main() { + char string[200] = {' '}; + + Stack stack; + init(&stack); + fgets(string, sizeof(string), stdin); + + for (int i = 0; i < 200; i++) { + char cur = string[i]; + if (cur == ' ') { + continue; + } + else if (cur == '\n') { + break; + } + + else if (cur == '(') { + push(&stack, cur); + } + + else if (cur == ')') { + while (stack.size > 0) { + Node* node = pop(&stack); + char value = (*node).value; + if (value == '(') { + break; + } + + printf("%c ", value); + } + } + else if (cur == '+' || cur == '-' || cur == '*' || cur == '/') { + int curPriority = getPriority(cur); + while (stack.size > 0) { + Node* node = pop(&stack); + char value = (*node).value; + + int valuePriority = getPriority(value); + if (valuePriority >= curPriority) { + printf("%c ", value); + } + else { + push(&stack, value); + free(node); + break; + } + } + push(&stack, cur); + } + + else { + printf("%c ", cur); + } + + } + + + while (stack.size > 0) { + Node* node = pop(&stack); + char value = (*node).value; + if (value == '(') { + break; + } + + printf("%c ", value); + } + + printf("\n"); + + + +} + +int getPriority(char cur) { + if (cur == '+' || cur == '-') { + return 1; + } + else if (cur == '*' || cur == '/') { + return 2; + } + + return -1000; +} From 7c6a7a73e953a64827f1c97be98de9477b7d3e10 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Wed, 15 Oct 2025 18:19:41 +0300 Subject: [PATCH 3/7] Print FIX --- 5/shuntingYard.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/5/shuntingYard.c b/5/shuntingYard.c index b24e856..3b91d31 100644 --- a/5/shuntingYard.c +++ b/5/shuntingYard.c @@ -10,12 +10,11 @@ void main() { init(&stack); fgets(string, sizeof(string), stdin); + int countSpace = 0; + for (int i = 0; i < 200; i++) { char cur = string[i]; - if (cur == ' ') { - continue; - } - else if (cur == '\n') { + if (cur == '\n') { break; } @@ -31,7 +30,7 @@ void main() { break; } - printf("%c ", value); + printf(" %c", value); } } else if (cur == '+' || cur == '-' || cur == '*' || cur == '/') { @@ -42,7 +41,7 @@ void main() { int valuePriority = getPriority(value); if (valuePriority >= curPriority) { - printf("%c ", value); + printf(" %c", value); } else { push(&stack, value); @@ -54,7 +53,16 @@ void main() { } else { - printf("%c ", cur); + if (cur == ' ' && countSpace == 0) { + printf("%c", cur); + countSpace += 1; + } + else if (cur != ' ') { + printf("%c", cur); + countSpace = 0; + } + + } } @@ -67,7 +75,7 @@ void main() { break; } - printf("%c ", value); + printf(" %c", value); } printf("\n"); From 9872b9b76c30aed7f77c67a1f126896a41648964 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Sun, 16 Nov 2025 16:04:06 +0300 Subject: [PATCH 4/7] Moved --- 5/shuntingYard.c | 96 ------------------------------------------------ 5/stack.c | 46 ----------------------- 5/stack.h | 18 --------- 3 files changed, 160 deletions(-) delete mode 100644 5/shuntingYard.c delete mode 100644 5/stack.c delete mode 100644 5/stack.h diff --git a/5/shuntingYard.c b/5/shuntingYard.c deleted file mode 100644 index 3b91d31..0000000 --- a/5/shuntingYard.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "stack.h" - -int getPriority(char cur); - - -void main() { - char string[200] = {' '}; - - Stack stack; - init(&stack); - fgets(string, sizeof(string), stdin); - - int countSpace = 0; - - for (int i = 0; i < 200; i++) { - char cur = string[i]; - if (cur == '\n') { - break; - } - - else if (cur == '(') { - push(&stack, cur); - } - - else if (cur == ')') { - while (stack.size > 0) { - Node* node = pop(&stack); - char value = (*node).value; - if (value == '(') { - break; - } - - printf(" %c", value); - } - } - else if (cur == '+' || cur == '-' || cur == '*' || cur == '/') { - int curPriority = getPriority(cur); - while (stack.size > 0) { - Node* node = pop(&stack); - char value = (*node).value; - - int valuePriority = getPriority(value); - if (valuePriority >= curPriority) { - printf(" %c", value); - } - else { - push(&stack, value); - free(node); - break; - } - } - push(&stack, cur); - } - - else { - if (cur == ' ' && countSpace == 0) { - printf("%c", cur); - countSpace += 1; - } - else if (cur != ' ') { - printf("%c", cur); - countSpace = 0; - } - - - } - - } - - - while (stack.size > 0) { - Node* node = pop(&stack); - char value = (*node).value; - if (value == '(') { - break; - } - - printf(" %c", value); - } - - printf("\n"); - - - -} - -int getPriority(char cur) { - if (cur == '+' || cur == '-') { - return 1; - } - else if (cur == '*' || cur == '/') { - return 2; - } - - return -1000; -} diff --git a/5/stack.c b/5/stack.c deleted file mode 100644 index eaae60e..0000000 --- a/5/stack.c +++ /dev/null @@ -1,46 +0,0 @@ -#include "stack.h" - - -void init(Stack* stack) { - (*stack).top = NULL; - (*stack).size = 0; -} - -void push(Stack* stack, char value) { - Node* new_node = malloc(sizeof(Node)); - - (*new_node).value = value; - (*new_node).next = (*stack).top; - - (*stack).top = new_node; - (*stack).size++; -} - - - -Node* pop(Stack* stack) { - if ((*stack).top == NULL) { - return NULL; - } - - Node* out = (*stack).top; - (*stack).top = (*out).next; - - (*stack).size--; - - return out; -} - -void printStack(Stack* stack) { - if ((*stack).size == 0) { - printf("\n"); - return; - } - Node* current = (*stack).top; - do { - printf("%c ", (*current).value); - current = (*current).next; - } - while (current != NULL); - printf("\n"); -} diff --git a/5/stack.h b/5/stack.h deleted file mode 100644 index b2d5857..0000000 --- a/5/stack.h +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -typedef struct Node { - char value; - struct Node* next; -} Node; - -typedef struct Stack { - Node* top; - int size; -} Stack; - - -void init(Stack* stack); -void push(Stack* stack, char value); -Node* pop(Stack* stack); -void printStack(Stack* stack); From 7d68dc144f82d96a8c2150cd7ef3d5a63621bc0c Mon Sep 17 00:00:00 2001 From: stuffacc Date: Sun, 16 Nov 2025 16:05:15 +0300 Subject: [PATCH 5/7] Cmake --- 5/shunting_yard/CMakeLists.txt | 13 +++++ 5/shunting_yard/shuntingYard.c | 96 ++++++++++++++++++++++++++++++++++ 5/shunting_yard/stack.c | 46 ++++++++++++++++ 5/shunting_yard/stack.h | 18 +++++++ 4 files changed, 173 insertions(+) create mode 100644 5/shunting_yard/CMakeLists.txt create mode 100644 5/shunting_yard/shuntingYard.c create mode 100644 5/shunting_yard/stack.c create mode 100644 5/shunting_yard/stack.h diff --git a/5/shunting_yard/CMakeLists.txt b/5/shunting_yard/CMakeLists.txt new file mode 100644 index 0000000..650cd47 --- /dev/null +++ b/5/shunting_yard/CMakeLists.txt @@ -0,0 +1,13 @@ +# Устанавливаем минимальную версию CMake +cmake_minimum_required(VERSION 3.25) +# Указываем название проекта и используемый язык(и) +project(ShuntingYard C) + +# Перечисляем библиотеки +add_library(Stack stack.c) + +# Указываем исполняемый файл +add_executable(ShuntingYard shuntingYard.c) +# Связываемся с библиотеками +target_link_libraries(ShuntingYard PRIVATE Stack) + diff --git a/5/shunting_yard/shuntingYard.c b/5/shunting_yard/shuntingYard.c new file mode 100644 index 0000000..3b91d31 --- /dev/null +++ b/5/shunting_yard/shuntingYard.c @@ -0,0 +1,96 @@ +#include "stack.h" + +int getPriority(char cur); + + +void main() { + char string[200] = {' '}; + + Stack stack; + init(&stack); + fgets(string, sizeof(string), stdin); + + int countSpace = 0; + + for (int i = 0; i < 200; i++) { + char cur = string[i]; + if (cur == '\n') { + break; + } + + else if (cur == '(') { + push(&stack, cur); + } + + else if (cur == ')') { + while (stack.size > 0) { + Node* node = pop(&stack); + char value = (*node).value; + if (value == '(') { + break; + } + + printf(" %c", value); + } + } + else if (cur == '+' || cur == '-' || cur == '*' || cur == '/') { + int curPriority = getPriority(cur); + while (stack.size > 0) { + Node* node = pop(&stack); + char value = (*node).value; + + int valuePriority = getPriority(value); + if (valuePriority >= curPriority) { + printf(" %c", value); + } + else { + push(&stack, value); + free(node); + break; + } + } + push(&stack, cur); + } + + else { + if (cur == ' ' && countSpace == 0) { + printf("%c", cur); + countSpace += 1; + } + else if (cur != ' ') { + printf("%c", cur); + countSpace = 0; + } + + + } + + } + + + while (stack.size > 0) { + Node* node = pop(&stack); + char value = (*node).value; + if (value == '(') { + break; + } + + printf(" %c", value); + } + + printf("\n"); + + + +} + +int getPriority(char cur) { + if (cur == '+' || cur == '-') { + return 1; + } + else if (cur == '*' || cur == '/') { + return 2; + } + + return -1000; +} diff --git a/5/shunting_yard/stack.c b/5/shunting_yard/stack.c new file mode 100644 index 0000000..eaae60e --- /dev/null +++ b/5/shunting_yard/stack.c @@ -0,0 +1,46 @@ +#include "stack.h" + + +void init(Stack* stack) { + (*stack).top = NULL; + (*stack).size = 0; +} + +void push(Stack* stack, char value) { + Node* new_node = malloc(sizeof(Node)); + + (*new_node).value = value; + (*new_node).next = (*stack).top; + + (*stack).top = new_node; + (*stack).size++; +} + + + +Node* pop(Stack* stack) { + if ((*stack).top == NULL) { + return NULL; + } + + Node* out = (*stack).top; + (*stack).top = (*out).next; + + (*stack).size--; + + return out; +} + +void printStack(Stack* stack) { + if ((*stack).size == 0) { + printf("\n"); + return; + } + Node* current = (*stack).top; + do { + printf("%c ", (*current).value); + current = (*current).next; + } + while (current != NULL); + printf("\n"); +} diff --git a/5/shunting_yard/stack.h b/5/shunting_yard/stack.h new file mode 100644 index 0000000..b2d5857 --- /dev/null +++ b/5/shunting_yard/stack.h @@ -0,0 +1,18 @@ +#include +#include + +typedef struct Node { + char value; + struct Node* next; +} Node; + +typedef struct Stack { + Node* top; + int size; +} Stack; + + +void init(Stack* stack); +void push(Stack* stack, char value); +Node* pop(Stack* stack); +void printStack(Stack* stack); From ebc1958146a41c0dde19763c5ea23326cd2eb6e5 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Wed, 24 Dec 2025 19:15:17 +0300 Subject: [PATCH 6/7] all in one --- 5/{shunting_yard => }/CMakeLists.txt | 7 ++++++- 5/{shunting_yard => }/shuntingYard.c | 0 5/{shunting_yard => }/stack.c | 0 5/{shunting_yard => }/stack.h | 0 4 files changed, 6 insertions(+), 1 deletion(-) rename 5/{shunting_yard => }/CMakeLists.txt (72%) rename 5/{shunting_yard => }/shuntingYard.c (100%) rename 5/{shunting_yard => }/stack.c (100%) rename 5/{shunting_yard => }/stack.h (100%) diff --git a/5/shunting_yard/CMakeLists.txt b/5/CMakeLists.txt similarity index 72% rename from 5/shunting_yard/CMakeLists.txt rename to 5/CMakeLists.txt index 650cd47..3af5bfa 100644 --- a/5/shunting_yard/CMakeLists.txt +++ b/5/CMakeLists.txt @@ -1,13 +1,18 @@ # Устанавливаем минимальную версию CMake cmake_minimum_required(VERSION 3.25) # Указываем название проекта и используемый язык(и) +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD_REQUIRED ON) + +project(AdvancedBalance C) project(ShuntingYard C) # Перечисляем библиотеки add_library(Stack stack.c) # Указываем исполняемый файл +add_executable(AdvancedBalance advanced_balance.c) add_executable(ShuntingYard shuntingYard.c) # Связываемся с библиотеками +target_link_libraries(AdvancedBalance PRIVATE Stack) target_link_libraries(ShuntingYard PRIVATE Stack) - diff --git a/5/shunting_yard/shuntingYard.c b/5/shuntingYard.c similarity index 100% rename from 5/shunting_yard/shuntingYard.c rename to 5/shuntingYard.c diff --git a/5/shunting_yard/stack.c b/5/stack.c similarity index 100% rename from 5/shunting_yard/stack.c rename to 5/stack.c diff --git a/5/shunting_yard/stack.h b/5/stack.h similarity index 100% rename from 5/shunting_yard/stack.h rename to 5/stack.h From 31cf706cf151594623b31619838acf2579466de9 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Wed, 24 Dec 2025 19:18:31 +0300 Subject: [PATCH 7/7] =?UTF-8?q?=D0=BE=D0=BF=D1=8F=D1=82=D1=8C=20webkit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 5/shuntingYard.c | 164 ++++++++++++++++++++++------------------------- 5/stack.c | 64 +++++++++--------- 5/stack.h | 11 ++-- 3 files changed, 114 insertions(+), 125 deletions(-) diff --git a/5/shuntingYard.c b/5/shuntingYard.c index 3b91d31..3001aa7 100644 --- a/5/shuntingYard.c +++ b/5/shuntingYard.c @@ -2,95 +2,85 @@ int getPriority(char cur); +void main() +{ + char string[200] = { ' ' }; -void main() { - char string[200] = {' '}; - - Stack stack; - init(&stack); - fgets(string, sizeof(string), stdin); - - int countSpace = 0; - - for (int i = 0; i < 200; i++) { - char cur = string[i]; - if (cur == '\n') { - break; - } - - else if (cur == '(') { - push(&stack, cur); - } - - else if (cur == ')') { - while (stack.size > 0) { - Node* node = pop(&stack); - char value = (*node).value; - if (value == '(') { - break; - } - - printf(" %c", value); - } - } - else if (cur == '+' || cur == '-' || cur == '*' || cur == '/') { - int curPriority = getPriority(cur); - while (stack.size > 0) { - Node* node = pop(&stack); - char value = (*node).value; - - int valuePriority = getPriority(value); - if (valuePriority >= curPriority) { - printf(" %c", value); - } - else { - push(&stack, value); - free(node); - break; - } - } - push(&stack, cur); - } - - else { - if (cur == ' ' && countSpace == 0) { - printf("%c", cur); - countSpace += 1; - } - else if (cur != ' ') { - printf("%c", cur); - countSpace = 0; - } - - - } - - } - - - while (stack.size > 0) { - Node* node = pop(&stack); - char value = (*node).value; - if (value == '(') { - break; - } - - printf(" %c", value); - } - - printf("\n"); - - - -} + Stack stack; + init(&stack); + fgets(string, sizeof(string), stdin); + + int countSpace = 0; + + for (int i = 0; i < 200; i++) { + char cur = string[i]; + if (cur == '\n') { + break; + } + + else if (cur == '(') { + push(&stack, cur); + } + + else if (cur == ')') { + while (stack.size > 0) { + Node* node = pop(&stack); + char value = (*node).value; + if (value == '(') { + break; + } + + printf(" %c", value); + } + } else if (cur == '+' || cur == '-' || cur == '*' || cur == '/') { + int curPriority = getPriority(cur); + while (stack.size > 0) { + Node* node = pop(&stack); + char value = (*node).value; -int getPriority(char cur) { - if (cur == '+' || cur == '-') { - return 1; + int valuePriority = getPriority(value); + if (valuePriority >= curPriority) { + printf(" %c", value); + } else { + push(&stack, value); + free(node); + break; + } + } + push(&stack, cur); } - else if (cur == '*' || cur == '/') { - return 2; + + else { + if (cur == ' ' && countSpace == 0) { + printf("%c", cur); + countSpace += 1; + } else if (cur != ' ') { + printf("%c", cur); + countSpace = 0; + } + } + } + + while (stack.size > 0) { + Node* node = pop(&stack); + char value = (*node).value; + if (value == '(') { + break; } - - return -1000; + + printf(" %c", value); + } + + printf("\n"); +} + +int getPriority(char cur) +{ + if (cur == '+' || cur == '-') { + return 1; + } else if (cur == '*' || cur == '/') { + return 2; + } + + return -1000; } diff --git a/5/stack.c b/5/stack.c index eaae60e..447a011 100644 --- a/5/stack.c +++ b/5/stack.c @@ -1,46 +1,46 @@ #include "stack.h" - -void init(Stack* stack) { - (*stack).top = NULL; - (*stack).size = 0; +void init(Stack* stack) +{ + (*stack).top = NULL; + (*stack).size = 0; } -void push(Stack* stack, char value) { - Node* new_node = malloc(sizeof(Node)); - - (*new_node).value = value; - (*new_node).next = (*stack).top; +void push(Stack* stack, char value) +{ + Node* new_node = malloc(sizeof(Node)); + + (*new_node).value = value; + (*new_node).next = (*stack).top; - (*stack).top = new_node; - (*stack).size++; + (*stack).top = new_node; + (*stack).size++; } +Node* pop(Stack* stack) +{ + if ((*stack).top == NULL) { + return NULL; + } + Node* out = (*stack).top; + (*stack).top = (*out).next; -Node* pop(Stack* stack) { - if ((*stack).top == NULL) { - return NULL; - } + (*stack).size--; - Node* out = (*stack).top; - (*stack).top = (*out).next; - - (*stack).size--; - - return out; + return out; } -void printStack(Stack* stack) { - if ((*stack).size == 0) { - printf("\n"); - return; - } - Node* current = (*stack).top; - do { - printf("%c ", (*current).value); - current = (*current).next; - } - while (current != NULL); +void printStack(Stack* stack) +{ + if ((*stack).size == 0) { printf("\n"); + return; + } + Node* current = (*stack).top; + do { + printf("%c ", (*current).value); + current = (*current).next; + } while (current != NULL); + printf("\n"); } diff --git a/5/stack.h b/5/stack.h index b2d5857..7609179 100644 --- a/5/stack.h +++ b/5/stack.h @@ -1,17 +1,16 @@ -#include #include +#include typedef struct Node { - char value; - struct Node* next; + char value; + struct Node* next; } Node; typedef struct Stack { - Node* top; - int size; + Node* top; + int size; } Stack; - void init(Stack* stack); void push(Stack* stack, char value); Node* pop(Stack* stack);