Conversation
| { | ||
| push(&head, (postfixEntry[counter] - '0')); | ||
| } | ||
| else |
There was a problem hiding this comment.
Чтобы такой длинный else не писать, можно было continue в if сделать (только counter++ не потерять)
| return answer; | ||
| } | ||
|
|
||
| int main() |
There was a problem hiding this comment.
Лучше main делать в отдельном файле, иначе не получится просто скопировать файл с convertFromThePostfixForm для переиспользования в другом проекте
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| int convertFromThePostfixForm(char* postfixEntry) |
There was a problem hiding this comment.
Просили посчитать выражение, а не сконвертировать. Название функции запутывающее.
| int firstNumber = 0; | ||
| int secondNumber = 0; |
There was a problem hiding this comment.
Эти штуки вне цикла не нужны, надо их объявлять в месте первого использования
|
|
||
| while (postfixEntry[counter] != '\0') | ||
| { | ||
| if (postfixEntry[counter] >= (int)('0') && postfixEntry[counter] <= (int)('9')) |
There was a problem hiding this comment.
Совершенно незачем кастать к int. char-ы --- это обычные числа, разве что странно записывающиеся, все сравнения и арифметические операции для них тоже работают.
| } | ||
| counter++; | ||
| } | ||
| int answer = pop(&head); |
There was a problem hiding this comment.
Если после этого стек не пуст, это тоже ошибка.
| char postfixEntry[250] = {'\0'}; | ||
| printf("enter the expression in postfix form\n"); | ||
| scanf_s("%s", postfixEntry, (unsigned)_countof(postfixEntry)); | ||
| int answer = convertFromThePostfixForm(postfixEntry); |
There was a problem hiding this comment.
Вообще, больше const-ов этой программе бы не помешало
| { | ||
| return; | ||
| } | ||
| newStack -> value = element; |
There was a problem hiding this comment.
| newStack -> value = element; | |
| newStack->value = element; |
Обращение к полю никогда пробелами не выделяется, хотя, казалось бы, это бинарный оператор, так что должно бы
|
|
||
| int pop(Stack** head) | ||
| { | ||
| int element = (*head) -> value; |
| { | ||
| int element = (*head) -> value; | ||
| Stack* temporary = *head; | ||
| Stack* help = (*head) -> next; |
There was a problem hiding this comment.
| Stack* help = (*head) -> next; | |
| *head = (*head) -> next; |
Вы же уже запомнили текущую голову
| #pragma once | ||
| #include <stdbool.h> | ||
|
|
||
| // Function that translates an expression from a postfix form |
| { | ||
| int value; | ||
| struct Stack* next; | ||
| }Stack; |
There was a problem hiding this comment.
| }Stack; | |
| } Stack; |
| struct Stack* next; | ||
| }Stack; | ||
|
|
||
| // Function for test empty stack |
There was a problem hiding this comment.
| // Function for test empty stack | |
| // Function for testing if stack is empty |
Например. Иначе как-то не по-английски.
| Stack* temporary = *head; | ||
| *head = (*head)->next; | ||
| free(temporary); | ||
| return element; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| { | ||
| if (*head != NULL) | ||
| { | ||
| int element = (*head)->value; |
There was a problem hiding this comment.
| int element = (*head)->value; | |
| const int element = (*head)->value; |
| @@ -0,0 +1,70 @@ | |||
| #include "../../Stack/Stack/Stack.h" | |||
| #include "../../Stack/Stack/StackTest.h" | |||
There was a problem hiding this comment.
StackTest, кажется, тут не нужен. Вообще, если "боевой" код зависит от тестового, то что-то не так.
| { | ||
| if (postfixEntry[counter] >= '0' && postfixEntry[counter] <= '9') | ||
| { | ||
| push(&head, (postfixEntry[counter] - '0')); |
There was a problem hiding this comment.
| push(&head, (postfixEntry[counter] - '0')); | |
| push(&head, postfixEntry[counter] - '0'); |
| int secondNumber = 0; | ||
| int firstNumber = 0; | ||
| secondNumber = pop(&head, ©); |
There was a problem hiding this comment.
Не-а, переменные должны объявляться в месте первого использования
| } | ||
| int secondNumber = 0; | ||
| int firstNumber = 0; | ||
| secondNumber = pop(&head, ©); |
There was a problem hiding this comment.
copy может быть никак не связана с check, просто bool wasError= false; pop(&head, &wasError);. Тем более что имена этих переменных не годятся
| else | ||
| { | ||
| *check = false; | ||
| return 0; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
yurii-litvinov
left a comment
There was a problem hiding this comment.
Не пишите "fixed bugs", пишите, какие именно bugs были fixed. Ну и надо ещё чуть-чуть поправить (и всё-таки errno не использовать, это может быть не "чуть-чуть", но было же нормально).
| @@ -0,0 +1,36 @@ | |||
| #include "../../Stack/Stack/Stack.h" | |||
| #include "Postfix.h" | |||
There was a problem hiding this comment.
| #include "Postfix.h" | |
| #include "Postfix.h" |
| @@ -0,0 +1,36 @@ | |||
| #include "../../Stack/Stack/Stack.h" | |||
| #include "Postfix.h" | |||
| #include "postfixFormTest.h" | |||
There was a problem hiding this comment.
На самом деле этот файл называется с заглавной, так что под Linux программа не соберётся (там регистрозависимые файловые системы обычно, для них postfixFormTest.h и PostfixFormTest.h — это разные файлы). Поэтому обычно договариваются именовать либо всё с заглавной, либо всё со строчной.
| char postfixEntry[250] = { '\0' }; | ||
| printf("enter the expression in postfix form\n"); | ||
| scanf_s("%[^\n]s", postfixEntry, (unsigned)sizeof(postfixEntry)); | ||
| errno = 0; |
There was a problem hiding this comment.
Не стоит это использовать для возврата ошибок. Это глобальная переменная, глобальные переменные нельзя (тем более что конкретно тут можно с ума сойти проверять, что errno не перетрётся каким-нибудь вызовом стандартной библиотеки). Отдельный параметр для кода возврата ничем не хуже, разве что более громоздкий.
| const float answer = countTheExpression(postfixEntry); | ||
| if (errno == 1) | ||
| { | ||
| printf("Stack is empty"); |
There was a problem hiding this comment.
Я как пользователь функции ничего не знаю про стек. Тут надо более высокоуровневое сообщение об ошибке выводить, типа "у вас больше операторов, чем операндов", ну или просто что некорректное выражение.
yurii-litvinov
left a comment
There was a problem hiding this comment.
Да, теперь всё хорошо, зачтена
No description provided.