Skip to content
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

ADT set (tree) #13

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

ADT set (tree) #13

wants to merge 13 commits into from

Conversation

viktoriia-fomina
Copy link
Owner

ADT set seems ready. It lets user to add the value to set, delete the value from set, check if the value is in the set and it prints elements in ascending and descending orders.

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.

Тоже надо немного привести код в порядок

this->previous = nullptr;
this->next = nullptr;
data = 0;
}

Choose a reason for hiding this comment

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

Деструктор не нужен :)

struct Element
{
explicit Element(int data);
~Element();

Choose a reason for hiding this comment

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

И тут

if (isEmpty())
{
cout << "List is empty. Node can not be deleted\n";
}

Choose a reason for hiding this comment

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

return и дальше без else

}
else
{
this->~List();

Choose a reason for hiding this comment

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

Деструктор явно нельзя вызывать

while (temp->next != nullptr)
{
temp = temp->next;
}

Choose a reason for hiding this comment

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

Хм, можно было ему tail сделать

#pragma once
#include <iostream>

using namespace std;

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.

Мм, напоминаю

this->data = 0;
this->leftChild = nullptr;
this->rightChild = nullptr;
}

Choose a reason for hiding this comment

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

Тоже не нужно

// delete left subtree
while (head->leftChild != nullptr)
{
remove(maximum(head->leftChild));

Choose a reason for hiding this comment

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

Как сложно-то. Просто рекурсивно для каждого узла удаляем его потомков, затем его самого. Квадратичная трудоёмкость удаления тут ни к чему :)

else
{
cout << "There is no such menu option: " << number << endl << endl;
}

Choose a reason for hiding this comment

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

Может, тут лучше switch-case?

…element as I do not need it. Deleted constructed without pararemtrs as I do need it too
…tructors in element and node. Changed destructor in Set. Added switch instead of if-else in userInterface
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.

Ещё пара багов осталась, но в целом мне нравится. Зачтена.

Element* previous;
Element* next;
private:
Element();

Choose a reason for hiding this comment

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

= delete; :)

#pragma once
#include <iostream>

using namespace std;

Choose a reason for hiding this comment

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

Мм, напоминаю

}
else
{
if (node->data > data)

Choose a reason for hiding this comment

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

else if лучше без фигурных скобок

{
return false;
}
l.printInAscendingOrder();

Choose a reason for hiding this comment

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

Ну, обход дерева в прямом или обратном порядке делается за линейное время, добавление элементов дерева в сортированный список --- за квадратичное :)

switch (number)
{
case 0:
break;

Choose a reason for hiding this comment

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

Не, этот break теперь выходит из ветки case-а, а не из цикла, так что из программы нельзя выйти :)

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