Skip to content

Eivasch-list#96

Open
eivasch wants to merge 8 commits into
tehnotrack:masterfrom
eivasch:eivasch-list
Open

Eivasch-list#96
eivasch wants to merge 8 commits into
tehnotrack:masterfrom
eivasch:eivasch-list

Conversation

@eivasch
Copy link
Copy Markdown

@eivasch eivasch commented Mar 18, 2017

No description provided.

}

private Node getNode(int idx) {
Node current = start;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

idx может быть отрицательный

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

То есть просто проверку сделать? И ошибку выкидывать, если что

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

лучше выдавать ошибку

* Односвязный список
*/
public class MyLinkedList extends List {
public class MyLinkedList extends List implements Stack, Queue {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

зачем наследовать LinkedList от List? они основаны на разных принципах хранения данных.
LinkedList'у не нужен массив элементов, который от наследует от List

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Это не я писала, это было в задании:

  • Должен наследовать List
  • Односвязный список

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

да, действительно. но то, что меня смутило - это то, что вы часть логики реализуете в абстрактном классе List и в каждом методе вызываете super() - это не очевидно. это не ошибка логики, работать будет. но если даже и выносить size в абстрактный класс, то я бы его меняла по необходимости. это дело вкуса скорее. не считаю за ошибку

* Метод, который может бросить ошибку должен быть отмечен как throws НазваниеИсключения
* как сделано для этого метода
*/
abstract int remove(int idx) throws NoSuchElementException;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

/**
* Получить элемент с позиции idx, бросить исключение, если позиция невалидная
*/
abstract int get(int idx) throws NoSuchElementException;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

аналогично

@eivasch
Copy link
Copy Markdown
Author

eivasch commented Apr 3, 2017

@asabelnikova вы про индекс, который в getNode?
Кстати, хотела спросить. Там лучше реализовать внутри проверку или нормально вызывать chekIdx, хоть он по идее относится к классу List?

@Override
void add(int item) {

int newSize = size() + 1;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

какая сложность на вставку будет, если каждый раз при заполнении листа увеличивать размер буфера на 1?
какая сложность будет, если увеличивать в n раз (например, в 2)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ого. Интересно. То есть предлагаете увеличить сразу в два раза?
Но тогда же придется заводить еще одну переменную .Чтобы был размер массива и реальный размер массива.
Или я не поняла мысль?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

вам нужна переменная только для размера списка.
размер буфера вы можете получить list.length

int remove(int idx) throws NoSuchElementException {
return 0;
check_idx(idx);
int newSize = listSize - 1;
Copy link
Copy Markdown
Collaborator

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