Informatikks1/LinkedList.java

55 lines
1009 B
Java

public class LinkedList
{
private Node start;
public LinkedList(){
}
public void einfuegen(int zahl){
Node neu = new Node();
neu.wert = zahl;
if (this.start == null) {
this.start = neu;
Node current = this.start;
while (current.next != null) {
current = current.next;
}
current.next = neu;
}
}
public int laenge(){
int count = 0;
Node current = this.start;
while(current != null) {
current = current.next;
count++;
}
return count;
}
public String toString(){
String result = " ";
Node current = this.start;
while( current != null) {
result += current.wert + ",";
current = current.next;
}
return result;
}
public int erste(){
int tmp = this.start.wert;
this.start = this.start.next;
return tmp;
}
public int getNteZahl(int n){
return 0;
}
}