Skip to content

Conversation

@MinyazevR
Copy link
Owner

No description provided.

Copy link

@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.

Название ветки и пулреквеста ужасно :) И программа не объясняет себя, а просто работает, так нельзя. Писать надо не для себя, а для людей, которые это читать будут.

struct Node* parent;
char value;
int number;
char help;

Choose a reason for hiding this comment

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

image
Не называйте переменные "help", это мило, но не мнемонично.

return root->number;
}

bool compare(char symbol)

Choose a reason for hiding this comment

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

Тоже название не очень. compare чего с чем? Тем более тут проверяется, является ли символ оператором, так что я бы isOperator это назвал

|| symbol == '*' || symbol == '/';
}

Node* buildTree(char* array)

Choose a reason for hiding this comment

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

const char* array
Чтобы явно сказать всем, что мы не собираемся менять элементы массива, и разрешить, в частности, принимать строковые литералы сюда, что сделает работу с этой функцией в сотню раз более удобной

Node* newRoot = (Node*)calloc(1, sizeof(Node));
if (newRoot == NULL)
{
return NULL;

Choose a reason for hiding this comment

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

Так всё построенное до этого дерево потеряется

Comment on lines 11 to 12
char value;
int number;

Choose a reason for hiding this comment

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

Ну тоже переменные названы замечательно, непонятно, кто из них кто.

{
Node* firstTree = createTree();
firstTree = buildTree("- * + 4 3 5 * 2 7");
firstTree = returnHead(firstTree);

Choose a reason for hiding this comment

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

Разве не buildTree должна была бы это делать?

Comment on lines 28 to 34
Node* rightSon(Node* root);

// Function for accessing the left son of the current root
Node* leftSon(Node* root);

// Function for accessing the parent of the current root
Node* parent(Node* root);

Choose a reason for hiding this comment

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

Не слишком ли много дерево раскрывает о себе? Сокрытие деталей реализации тут не очень, и принцип минимальности интерфейса абстракции тоже страдает

}
char expression[100] = { '\0' };
return buildTree(fgets(expression, 100, file));
fclose(file);

Choose a reason for hiding this comment

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

Оно так не работает :)

#include "../../ParsingTree/ParsingTree/ParsingTree.h"
#include <stdio.h>

Node* readExpression(Node* tree, const char* fileName, int* error)

Choose a reason for hiding this comment

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

tree не используется, что намекает на утечку памяти

tree = returnHead(tree);
findAnswer(tree);
const int answer = returnAnswer(tree);
printf("Meaning of the expression : %d\n", answer);

Choose a reason for hiding this comment

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

"meaning" --- это "значение" в смысле "смысл". Тут правильно "value" или "result" или что-то такое.

@MinyazevR MinyazevR changed the title Solving the problem InteractiveModeForWorkingWithTheParseTree Nov 19, 2021
@MinyazevR MinyazevR changed the title InteractiveModeForWorkingWithTheParseTree Interactive mode for working with the parse tree Nov 19, 2021
Copy link

@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.

Утечки памяти тоже надо поправить

Choose a reason for hiding this comment

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

На самом деле, был ли узел посещён — это состояние обхода, а не свойство узла, потому что если мы два обхода параллельно запустим, всё сломается. Да даже если два последовательно, сбросится ли статус isVisitedNode? Но если хотите так, то можно не править.

Choose a reason for hiding this comment

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

У дерева нет головы, у него есть корень. Но если бы мы назвали эту функцию returnRoot, было бы не очень, потому что параметр у неё называется root. Это плохо.

Choose a reason for hiding this comment

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

Вот, например, тут — это же не корень, это узел

Choose a reason for hiding this comment

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

Эта строка — самое нелогичное, что я видел сегодня. Если оператор, то узел не посещён, иначе посещён, что?

Choose a reason for hiding this comment

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

Тут можно уже без else, выше ветка на return заканчивается. Это сэкономит уровень отступа.

Choose a reason for hiding this comment

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

Очень длинная строчка, надо перенести на несколько

Choose a reason for hiding this comment

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

Лучше было выводить в строку, потому что иначе эту функцию не протестировать, но ладно, пусть так

Choose a reason for hiding this comment

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

Тесты проверяют не тот формат записи, что просили в условии, то есть не доказывают, что программа работает как надо :)

Copy link

@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.

Почти всё ок, но надо поддержать целые числа

Choose a reason for hiding this comment

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

Так "целые числа в качестве аргументов" не получится поддержать. Например, "-15".

Choose a reason for hiding this comment

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

Да ну, проще было "если оператор, распечатать скобку, знак, вызваться рекурсивно от левого и правого сына, распечатать закрывающую скобку. Если операнд, просто число распечатать".

Choose a reason for hiding this comment

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

Тоже не уверен на самом деле, что это надо хранить в дереве. Всё равно ведь пересчитываете каждый раз. return findAnswer(root->leftSon, error); тоже было бы ок.

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