public String get(int index) {
Node current = first.next;
if(current != last && current.value != null){
for(int i = 0; i<index; i++){
current = current.next;
}
return current.value;
}
return null;
}
вроде всё должно быть верно, проверку проходит, ошибки не выскакивают, но, валидатор ругаетсяpackage com.javarush.task.pro.task13.task1314;
public class StringLinkedList {
private Node first = new Node();
private Node last = new Node();
public StringLinkedList() {
first.next = last;
last.prev = first;
}
public void add(String value) {
Node newNode = new Node();
newNode.value = value;
Node prevLast = last.prev;
prevLast.next = newNode;
newNode.prev = prevLast;
newNode.next = last;
last.prev = newNode;
}
public String get(int index) {
Node current = first.next;
if(current != last && current.value != null){
for(int i = 0; i<index; i++){
current = current.next;
}
return current.value;
}
return null;
}
public static class Node {
private Node prev;
private String value;
private Node next;
}
}