Skip to content

Lesson 39 queue1 for review#91

Open
Binary-Cat-01 wants to merge 4 commits intoKFalcon2022:for-prfrom
Binary-Cat-01:lesson_39_queue1_for_review
Open

Lesson 39 queue1 for review#91
Binary-Cat-01 wants to merge 4 commits intoKFalcon2022:for-prfrom
Binary-Cat-01:lesson_39_queue1_for_review

Conversation

@Binary-Cat-01
Copy link
Copy Markdown

No description provided.

public static void main(String[] args) {
LinkedList<Integer> integers = new LinkedList<>();

integers.reverse();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

на пустом списке неинтересно:)


public E getTop() {
if (size == 0) {
throw new ElementNotFoundException();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

В общем-то, не зазорно и null тут вернуть. Но это мелочи

}

public void delete(Object object) {
if (top != null) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Вложенность лучше делать минимальной.

if (top == null) {
throw new ElementNotFoundException();
}

// код, который сейчас в if

даст тот же результат, но читать будет легче

throw new ElementNotFoundException();
}

public void deleteAllWithEvenHash() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

вот тут тонкий момент. Откровенно говоря, общей коллекции и близко не нужен такой метод - он решает какую-то узкую задачу, которая в общей функциональности структуры данных не нужна

Поэтому этот метод логичнее вынести за пределы коллекции. Его будет из-за этого сложнее реализовать. Но это будет намного правильнее с точки зрения дизайна системы

}
}

private boolean isReversible() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

не самое удачное название. reversible - это скорее про обратимость, а не разворачиваемость взад-назад:) опять же, мелкое замечание

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ну и да. В чем проблема развернуть пустой или одноэлементный список?) даже делать ничего не надо

}

public void alternativeReverse() {
if (isReversible()) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

опять же, if стоит инвертировать

this.next = next;
}

private boolean hasEvenHash() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

тот же момент, что и с методом удаления по четному хэшу. Этой функциональности не место в классе общего назначения

public String toString() {
return linkedList.toString();
}
} No newline at end of file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Тут все ок:)

if (first.isLast()) {
last = first;
} else {
first.next.previous = first;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

first.next.previous - чет намудрил. А не поленился бы старый first вынести в отдельную переменную - было бы красиво и просто)

}

private void swapFistAndLast() {
Node<E> temp = first;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

не уверен, что для этого нужен отдельный метод

last = temp;
}

private void delete(Node<E> current) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

deleteNode было бы более понятным

return value.hashCode() % 2 == 0;
}

private void swapNextAndPrevious() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

кажется избыточной функциональностью. Но имеет право на жизнь

previous = temp;
}
}
} No newline at end of file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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

private final LinkedList<E> linkedList;

public Queue() {
this.linkedList = new LinkedList<>();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

как будто можно это прописать при декларации поля. Но не критично

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