-
Notifications
You must be signed in to change notification settings - Fork 0
Sorting station #23
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: main
Are you sure you want to change the base?
Sorting station #23
Conversation
fixed bugs
adding a function that returns the value of an element from the top o…
…k-1-sem into SortingStation
fixed bugs
yurii-litvinov
left a comment
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.
Что-то неправильный ответ:
enter the expression in the infix form
1 - 2 + 3
1 2 3 + -
В инфиксной форме это (1 - 2) + 3, то есть 2, в постфиксной это 1 (2 3 +) -, то есть -4
Stack/Stack/Stack.c
Outdated
| char pop(Stack** head, int* error) | ||
| { | ||
| *error = 0; | ||
| if (*head != NULL) |
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.
Я бы тут обратил условие if на самом деле, чтобы весь содержательный код был не под if
sortStation/sortStation/Main.c
Outdated
| while (arrayToOutput[counter] != '\0') | ||
| { | ||
| printf("%c", arrayToOutput[counter]); | ||
| counter++; | ||
| } |
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.
Это же printf("%s", arrayToOutput);
sortStation/sortStation/Main.c
Outdated
| printf("enter the expression in the infix form\n"); | ||
| scanf_s("%[^\n]s", array, (unsigned)sizeof(array)); | ||
| int errorCode = 0; | ||
| char* arrayToOutput = translationIntoPostfixForm(array, &errorCode); |
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.
Можно аж так:
| char* arrayToOutput = translationIntoPostfixForm(array, &errorCode); | |
| const char* const arrayToOutput = translationIntoPostfixForm(array, &errorCode); |
| const char firstCorrectExpression[250] = "(7 - 6) * (7 - (6 - 4) * 2)"; | ||
| const char secondCorrectExpression[250] = "6 * (8 - 4) / 2 + 4"; | ||
| const char thirdCorrectExpression[250] = "3 - 4 * (5 + 5) / 2 + (7 - (4 - 6))"; | ||
| const char fourthCorrectExpression[250] = "2834 - 123 * (12 + 45 - (12 * (34 - 12) + 7))"; | ||
| const char fifthCorrectExpression[250] = "76 - 45 * (34 + 27)"; | ||
|
|
||
| const char firstIncorrectExpression[250] = "( 7 - 6 )"; | ||
| const char secondIncorrectExpression[250] = " 7-6"; | ||
| const char thirdIncorrectExpression[250] = "(7 - 3) * 4 - 5)"; | ||
| const char fourthIncorrectExpression[250] = "4 * ( 3 + 4)"; | ||
| const char fifthIncorrectExpression[250] = "12 - 8 / a "; |
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.
В этой задаче тоже можно было эти штуки прямо на месте писать, при вызове translationIntoPostfixForm
| #include "../../Stack/Stack/Stack.h" | ||
| #include <stdio.h> | ||
| #include <malloc.h> | ||
| #include <errno.h> |
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.
Это уже не нужно по идее
| if (array[counter - 1] == ' ') | ||
| { | ||
| deleteStack(&head); | ||
| *errorCode = 4; |
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.
Как-то Вы нетолерантны к лишним пробелам (как я при проверке домашек прямо). Можно было их просто пропускать
| counter++; | ||
| continue; | ||
| } | ||
| arrayToOutput[counterForTheOutputArray] = array[counter]; |
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.
Можно было проще, просто при выводе чего-либо в arrayToOutput добавлять ещё и пробел
| int counterForTheOutputArray = 0; | ||
| int counter = 0; | ||
| int error = 0 ; | ||
| char* arrayToOutput = (char*)malloc(1000 * sizeof(char)); |
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.
Можно было length(array) + 1 выделять, или 2 * length(array) + 1, если хотим красиво с пробелами
| *errorCode = 4; | ||
| return NULL; | ||
| } | ||
| while (!isEmpty(head) && top(&head, &error) == '*' || top(&head, &error) == '/') |
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.
Вот тут бы скобки поставить. Кажется, у && больший приоритет, чем у ||
| } | ||
| while (top(&head, &error) != '(') | ||
| { | ||
| if(!isEmpty(head)) |
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.
| if(!isEmpty(head)) | |
| if (!isEmpty(head)) |
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.
Не поправили :)
yurii-litvinov
left a comment
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.
Что-то эта домашка выбивается из структуры папок репозитория. А ещё, кстати, у Вас изменения к стеку делались не в ветке со стеком, а прямо в ветке конкретной задачи, так что чисто смерджить их в остальные задачи не получится. Надо навести порядок (то есть, может, неправильные коммиты откатить, и выложить изменения из них в ветку со стеком, а потом вмерджить её в ветки с задачами — только скопируйте себе решения куда-нибудь, а то сотрёте случайно всё). И ещё немного поправить.
Stack/Stack/Stack.c
Outdated
|
|
||
| int top(Stack** head, int* error) | ||
| { | ||
| *error = 0; |
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.
| *error = 0; | |
| *error = 0; |
| && strcmp("6 8 4 - * 2 / 4 +", translationIntoPostfixForm("6 * (8 - 4) / 2 + 4", &errors[1])) == 0 | ||
| && strcmp("3 4 5 5 + * 2 / - 7 4 6 - - +", translationIntoPostfixForm("3 - 4 * (5 + 5) / 2 + (7 - (4 - 6))", &errors[2])) == 0 | ||
| && strcmp("1 8 - 9 + 4 1 3 + * -", translationIntoPostfixForm("1 - 8 + 9 - 4 * (1 + 3)", &errors[3])) == 0 | ||
| && strcmp("1 2 - 3 +", translationIntoPostfixForm("1 - 2 + 3", &errors[4])) == 0 | ||
| && translationIntoPostfixForm("( 7 + * 2)", &errors[5]) == NULL | ||
| && translationIntoPostfixForm("7--", &errors[6]) == NULL | ||
| && translationIntoPostfixForm("(7 - 3) * 4 - 5)", &errors[7]) == NULL | ||
| && translationIntoPostfixForm("2 + 2)", &errors[8]) == NULL | ||
| && translationIntoPostfixForm("12 - 8 / a", &errors[9]) == NULL | ||
| && errors[0] == 0 | ||
| && errors[1] == 0 | ||
| && errors[2] == 0 | ||
| && errors[3] == 0 | ||
| && errors[4] == 0 | ||
| && errors[5] == 1 | ||
| && errors[6] == 1 | ||
| && errors[7] == 3 | ||
| && errors[8] == 3 | ||
| && errors[9] == 3; |
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.
Надо отступы перед && тут
| void addSpace(char* symbol) | ||
| { | ||
| *symbol = ' '; | ||
| } |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| arrayToOutput[counterForTheOutputArray] = array[counter]; | ||
| counterForTheOutputArray++; | ||
| addSpace(&arrayToOutput[counterForTheOutputArray++]); |
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.
Вот эти три строчки стоило сделать отдельной функцией
| arrayToOutput[counterForTheOutputArray] = array[counter]; | ||
| counterForTheOutputArray++; | ||
| addSpace(&arrayToOutput[counterForTheOutputArray++]); |
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.
Кстати, counterForTheOutputArray++ тут — побочный эффект, нехорошо (запрещено стайлгайдом делать два действия за раз, потому что за этим тяжело уследить при беглом прочтении программы)
| { | ||
| *errorCode = 1; | ||
| deleteStack(&head); | ||
| return NULL; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| #include <malloc.h> | ||
| #include <string.h> | ||
|
|
||
| bool isRepeatTheOperation(char operation) |
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.
Хм, почему "repeat"?
| return operation == '+' || operation == '-' || operation == '*' || operation == '/'; | ||
| } | ||
|
|
||
| bool isPriorityForDivisionandMultiplication(char operation) |
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.
| bool isPriorityForDivisionandMultiplication(char operation) | |
| bool isPriorityForDivisionAndMultiplication(char operation) |
| return operation == '+' || operation == '-' || operation == '*' || operation == '/'; | ||
| } | ||
|
|
||
| bool isPriorityForDivisionandMultiplication(char operation) |
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.
Ну и я бы его назвал как просто isDivisionOrMultiplication, а лучше сделал бы функцию, которая бы по данному символу возвращала его приоритет в виде числа, и сравнивал бы числа
| } | ||
| while (top(&head, &error) != '(') | ||
| { | ||
| if(!isEmpty(head)) |
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.
Не поправили :)
yurii-litvinov
left a comment
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.
Да, всё правильно, зачтена
| #include <malloc.h> | ||
| #include <string.h> | ||
|
|
||
| bool isSecondOperationInRow(char operation) |
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.
Это скорее просто isOperation, в самой функции ничего про SecondInRow нет, а функция не должна делать предположений о том, как её будут использовать (иначе её тяжело будет использовать в другом контексте).
No description provided.