-
Notifications
You must be signed in to change notification settings - Fork 0
Advance balance #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #include "stack.h" | ||
|
|
||
| void main() { | ||
| char string[200] = {' '}; | ||
|
|
||
| fgets(string, sizeof(string), stdin); | ||
| Stack stack; | ||
| init(&stack); | ||
|
|
||
| int res = 1; | ||
|
|
||
| for (int i = 0; i < 200; i++) { | ||
| if (string[i] == '\n') { | ||
| break; | ||
| } | ||
| else if ((string[i] == '(') || (string[i] == '[') || (string[i] == '{')) { | ||
| push(&stack, string[i]); | ||
| } | ||
|
|
||
| else if (string[i] == ')') { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а можно ли каждую скобку не раскопировать? |
||
| Node* pope = pop(&stack); | ||
| if (pope == NULL) { | ||
| res = 0; | ||
| break; | ||
| } | ||
| char popChar = (*pope).value; | ||
| if (popChar != '(') { | ||
| free(pope); | ||
| res = 0; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| else if (string[i] == ']') { | ||
| Node* pope = pop(&stack); | ||
| if (pope == NULL) { | ||
| res = 0; | ||
| break; | ||
| } | ||
| char popChar = (*pope).value; | ||
| if (popChar != '[') { | ||
| free(pope); | ||
| res = 0; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| else if (string[i] == '}') { | ||
| Node* pope = pop(&stack); | ||
| if (pope == NULL) { | ||
| res = 0; | ||
| break; | ||
| } | ||
| char popChar = (*pope).value; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pope->value |
||
| if (popChar != '{') { | ||
| free(pope); | ||
| res = 0; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (res == 0 || stack.size != 0) { | ||
| printf("Баланса нет\n"); | ||
| } | ||
| else { | ||
| printf("Баланс есть\n"); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. починить это везде, как я написал выше |
||
| printf("\n"); | ||
| return; | ||
| } | ||
| Node* current = (*stack).top; | ||
| do { | ||
| printf("%c ", (*current).value); | ||
| current = (*current).next; | ||
| } | ||
| while (current != NULL); | ||
| printf("\n"); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #include <stdlib.h> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. нет include guards |
||
| #include <stdio.h> | ||
|
|
||
| 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); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
что-то не так с форматированием, во всей программе