Hab meine eigne LinkedList geschrieben.
Bloss es gibt nen Fehler:
Meine insert-Methode funzt net, kann mir einer sagen , warum?
und die insert:
Dazu
Bloss es gibt nen Fehler:
Meine insert-Methode funzt net, kann mir einer sagen , warum?
Code:
public class LinkedList implements List{
protected Node head;
protected Node tail;
public LinkedList(){
this.head=new Node(null,tail);
this.tail=new Node(null,tail);
}
protected class Node{
public Node next;
public Person person;
public Node (Person person,Node next){
this.next=next;
this.person=person;
}
public Node getNext(){
return this.next;
}
public Person getPerson(){
return this.person;
}
}
Code:
public void insert(int i,Person person) {
if (i <= 0) {
throw new IndexOutOfBoundsException();
} else if (head.next == tail) {
Node nu = new Node(person, tail);
head.next = nu;
} else {
Node f;
int stelle = 0;
for (f = head.getNext(); f == tail; f = f.getNext()) {
stelle++;
if (stelle > i) {
Node g = new Node(person, f.getNext());
g.next = f;
}
}
}
}
Code:
LinkedList alpha = new LinkedList();
Person hugo=new Person("Hugo","Dietrich","1296","15478");
alpha.insert(1, hugo);