Skip to content

Conversation

@Binary-Cat-01
Copy link

No description provided.

return List.of(task0, task1, task2, task3, task4, task5, task6, task7, task8);
}

public static List<Task> getMiddleList() {
Copy link
Owner

Choose a reason for hiding this comment

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

методы, наверно, приватные должны быть

System.out.println("Корень дерева: " + tree.getRoot());

System.out.println("Содержимое дерева в порядке возрастания ширины (BFS):");
tree.breadthFirstSearchTraversal();
Copy link
Owner

Choose a reason for hiding this comment

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

никогда раньше не задумывался, как будет обход в ширину на английском. Но тут по смыслу тогда должно быть printBreadthFirstSearch()

System.out.println();

System.out.println("Содержимое дерева в порядке возрастания значений (DFS:inOrder):");
List<?> ascendingOrder = tree.getAscendingOrder();
Copy link
Owner

Choose a reason for hiding this comment

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

вот такой вариант лучше, чем sout внутри класса дерева. Пусть даже в случае с обходом в ширину возвращался бы List<List<?>>


public static void print(List<?> list) {
for (Object object : list) {
System.out.print(object);
Copy link
Owner

Choose a reason for hiding this comment

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

Как будто мало чем отличается от sout(list) в таком виде

private final Comparator<? super E> comparator;

public BinarySearchTree() {
comparator = null;
Copy link
Owner

Choose a reason for hiding this comment

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

избыточно

}

private Node<E> getMinNode(Node<E> localRoot) {
return (localRoot != null && localRoot.hasLeftChild()) ? getMinNode(localRoot.left) : localRoot;
Copy link
Owner

Choose a reason for hiding this comment

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

лишние скобки вокруг условия. Если без них кажется, что сливается тернарка - просто разнеси ее на разные строки, например, как ниже. Ибо если сливается без скобок - со скобками тоже будет сливаться:))

return localRoot != null && localRoot.hasLeftChild()
     ? getMinNode(localRoot.left)
     : localRoot;

if (comparator != null) {
return comparator.compare(keyValue, currentValue);
} else {
Comparable<E> comparable = (Comparable<E>) keyValue;
Copy link
Owner

Choose a reason for hiding this comment

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

избыточное выделение переменной, на мой взгляд


int route = getRouteByKey(key, localRoot.value);

return isSearchHit(route) ?
Copy link
Owner

Choose a reason for hiding this comment

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

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

}

public void put(E key) {
root = put(key, root);
Copy link
Owner

Choose a reason for hiding this comment

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

делать приватную перегрузку публичного метода - обычно так себе тема, на грани фола. Лучше приватный метод назвать иначе - аля putIntetnal()

Именно в твоем случае выглядит прилично, на мой взгляд, но в целом, особенно в классах логики, такого стоит избегать

public List<E> getAscendingOrder() {
List<E> list = new ArrayList<>();

inOrderToList(root, list);
Copy link
Owner

Choose a reason for hiding this comment

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

плохое название для метода

List<E> inorder = getInOrderList();
List<E> middles = new ArrayList<>(inorder.size());

middleExtraction(inorder, middles);
Copy link
Owner

Choose a reason for hiding this comment

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

опять же, неудачное название


middleExtraction(inorder, middles);

BinarySearchTree<E> balanced = new BinarySearchTree<E>(this.comparator);
Copy link
Owner

Choose a reason for hiding this comment

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

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


int route = getRouteByKey(key, localRoot.value);

return isSearchHit(route) ?
Copy link
Owner

Choose a reason for hiding this comment

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

.

}

private Node<E> removeFound(Node<E> found, Node<E> parent) {
Node<E> newborn = found.hasTwoChild() ? removeSuccessor(found, parent) : getFoundChild(found);
Copy link
Owner

Choose a reason for hiding this comment

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

лучше разнести ауты на отдельные строки

return result <= 0;
}

private boolean isSearchHit(int route) {
Copy link
Owner

Choose a reason for hiding this comment

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

на мой взгляд, чутка перемудрил с getRouteByKey() и isSearchHit()
В первом случае не очевиден смысл - хотя это просто compare/compareTo для нод, во втором - просто бесполезный метод:)

* <p>
* Итеративные алгоритмы поиска, добавления и удаления.
*/
public class BinarySearchTree_v2<E> {
Copy link
Owner

Choose a reason for hiding this comment

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

постараюсь в следующий раз посмотреть. Сейчас морально не готов разбираться в дереве с soft-delete:)

private int getRouteByKey(E keyValue, E currentValue) {
if (comparator != null) {
return comparator.compare(keyValue, currentValue);
} else {
Copy link
Owner

Choose a reason for hiding this comment

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

Забыл в первой версии добавить. else здесь не нужен - попадание в if выше уже гарантирует, что до этого кода не дойдет, т.к. в if'е есть return

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