Skip to content

Sorting station#23

Open
MinyazevR wants to merge 51 commits into
mainfrom
SortingStation
Open

Sorting station#23
MinyazevR wants to merge 51 commits into
mainfrom
SortingStation

Conversation

@MinyazevR
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown

@yurii-litvinov yurii-litvinov left a 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

Comment thread Stack/Stack/Stack.c Outdated
char pop(Stack** head, int* error)
{
*error = 0;
if (*head != NULL)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы тут обратил условие if на самом деле, чтобы весь содержательный код был не под if

Comment thread sortStation/sortStation/Main.c Outdated
Comment on lines +39 to +43
while (arrayToOutput[counter] != '\0')
{
printf("%c", arrayToOutput[counter]);
counter++;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это же printf("%s", arrayToOutput);

Comment thread 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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно аж так:

Suggested change
char* arrayToOutput = translationIntoPostfixForm(array, &errorCode);
const char* const arrayToOutput = translationIntoPostfixForm(array, &errorCode);

Comment on lines +7 to +17
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 ";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В этой задаче тоже можно было эти штуки прямо на месте писать, при вызове translationIntoPostfixForm

Comment thread sortStation/sortStation/SortStation.c Outdated
#include "../../Stack/Stack/Stack.h"
#include <stdio.h>
#include <malloc.h>
#include <errno.h>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это уже не нужно по идее

Comment thread sortStation/sortStation/SortStation.c Outdated
if (array[counter - 1] == ' ')
{
deleteStack(&head);
*errorCode = 4;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как-то Вы нетолерантны к лишним пробелам (как я при проверке домашек прямо). Можно было их просто пропускать

Comment thread sortStation/sortStation/SortStation.c Outdated
counter++;
continue;
}
arrayToOutput[counterForTheOutputArray] = array[counter];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно было проще, просто при выводе чего-либо в arrayToOutput добавлять ещё и пробел

Comment thread sortStation/sortStation/SortStation.c Outdated
int counterForTheOutputArray = 0;
int counter = 0;
int error = 0 ;
char* arrayToOutput = (char*)malloc(1000 * sizeof(char));
Copy link
Copy Markdown

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, если хотим красиво с пробелами

Comment thread sortStation/sortStation/SortStation.c Outdated
*errorCode = 4;
return NULL;
}
while (!isEmpty(head) && top(&head, &error) == '*' || top(&head, &error) == '/')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот тут бы скобки поставить. Кажется, у && больший приоритет, чем у ||

Comment thread sortStation/sortStation/SortStation.c Outdated
}
while (top(&head, &error) != '(')
{
if(!isEmpty(head))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!isEmpty(head))
if (!isEmpty(head))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не поправили :)

Copy link
Copy Markdown

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что-то эта домашка выбивается из структуры папок репозитория. А ещё, кстати, у Вас изменения к стеку делались не в ветке со стеком, а прямо в ветке конкретной задачи, так что чисто смерджить их в остальные задачи не получится. Надо навести порядок (то есть, может, неправильные коммиты откатить, и выложить изменения из них в ветку со стеком, а потом вмерджить её в ветки с задачами — только скопируйте себе решения куда-нибудь, а то сотрёте случайно всё). И ещё немного поправить.

Comment thread Stack/Stack/Stack.c Outdated

int top(Stack** head, int* error)
{
*error = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*error = 0;
*error = 0;

Comment on lines +9 to +27
&& 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;
Copy link
Copy Markdown

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.

Comment thread sortStation/sortStation/SortStation.c Outdated
Comment on lines +43 to +45
arrayToOutput[counterForTheOutputArray] = array[counter];
counterForTheOutputArray++;
addSpace(&arrayToOutput[counterForTheOutputArray++]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот эти три строчки стоило сделать отдельной функцией

Comment thread sortStation/sortStation/SortStation.c Outdated
Comment on lines +43 to +45
arrayToOutput[counterForTheOutputArray] = array[counter];
counterForTheOutputArray++;
addSpace(&arrayToOutput[counterForTheOutputArray++]);
Copy link
Copy Markdown

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.

Comment thread sortStation/sortStation/SortStation.c Outdated
#include <malloc.h>
#include <string.h>

bool isRepeatTheOperation(char operation)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хм, почему "repeat"?

Comment thread sortStation/sortStation/SortStation.c Outdated
return operation == '+' || operation == '-' || operation == '*' || operation == '/';
}

bool isPriorityForDivisionandMultiplication(char operation)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool isPriorityForDivisionandMultiplication(char operation)
bool isPriorityForDivisionAndMultiplication(char operation)

Comment thread sortStation/sortStation/SortStation.c Outdated
return operation == '+' || operation == '-' || operation == '*' || operation == '/';
}

bool isPriorityForDivisionandMultiplication(char operation)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну и я бы его назвал как просто isDivisionOrMultiplication, а лучше сделал бы функцию, которая бы по данному символу возвращала его приоритет в виде числа, и сравнивал бы числа

Comment thread sortStation/sortStation/SortStation.c Outdated
}
while (top(&head, &error) != '(')
{
if(!isEmpty(head))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не поправили :)

Copy link
Copy Markdown

@yurii-litvinov yurii-litvinov left a 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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это скорее просто isOperation, в самой функции ничего про SecondInRow нет, а функция не должна делать предположений о том, как её будут использовать (иначе её тяжело будет использовать в другом контексте).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants