у меня есть класс
public class AnimalList<Animal> {
private class Node<N> {
Node<N> prev;
Animal data;
Node<N> next;
Node() {
prev = null;
data = null;
next = null;
}
Node(Animal input) {
prev = null;
data = input;
next = null;
}
Node(Animal input, Node current) {
prev = current;
data = input;
if (current != null)
next = current.next;
current.next = this;
if (next != null)
next.prev = this;
}
}
private Node<Animal> first;
private Node<Animal> last;
private int counter;
AnimalList() {
first = null;
last = null;
counter = 0;
}
private boolean isEmpty() {
return counter == 0;
}
public Node<Animal> getNode(int position) {
if (position < 0)
throw new IllegalArgumentException();
if (isEmpty())
return null;
if (position >= counter - 1)
return last;
if (position == 0)
return first;
Node<Animal> animal = first;
for (int i = 0; i < position; i++)
animal = animal.next;
return animal;
}
public Animal getDataAt(int position) {
if (isEmpty())
throw new NullPointerException();
return getNode(position).data;
}
public void add(Animal input) {
if (input == null)
throw new IllegalArgumentException();
if (isEmpty()) {
first = new Node<Animal>(input);
last = first;
counter++;
return;
}
last = new Node<Animal>(input, last);
counter++;
}
public void addAtPosition(Animal input, int position) {
if (input == null || position < 0) throw new IllegalArgumentException();
if (position >= counter - 1) {
add(input);
return;
}
if(position == 0){
Node<Animal> anml = new Node<Animal>(input);
first.prev = anml;
anml.next = first;
first = anml;
counter++;
return;
}
Node<Animal> animal = getNode(position-1);
animal = new Node<Animal>(input, animal);
counter++;
}
public void deleteAtPosition(int position){
if(position < 0) throw new IllegalArgumentException();
if(position >= counter - 1){
Node<Animal> anima_l = getNode(counter-1);
anima_l = null;
}
else {
Node<Animal> animal = getNode(position);
animal = animal.next;
}
}
public void delete(Animal input){
if(input == null) throw new IllegalArgumentException();
if(isEmpty()) throw new NullPointerException();
if(!isEmpty()){
}
}
public String toString() {
String res = "";
Node<Animal> one = first;
while (one != null) {
res += one.data.toString() + " ";
one = one.next;
}
return res;
}
}
как мне дописать удаление элемента по String и по номеру элемента?
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
Как реализованы методы по типу equals? Я понимаю, конечно же, что метод equals должен вызвать объект: собственно, в этом и вопросКак он так написан,...
Допустим, есть игра в которой 2 режимаПри одном режиме шарики от стен отскакивают, а при другом не отскакивают