diff --git a/LinkedList.java b/LinkedList.java index 9295b78..74abfa9 100644 --- a/LinkedList.java +++ b/LinkedList.java @@ -1,12 +1,12 @@ -public class LinkedList +public class LinkedList { - private Node start; + private Node start; public LinkedList(){ } - public void einfuegen(int zahl){ + public void einfuegen(T zahl){ Node neu = new Node(); neu.wert = zahl; if (this.start == null) { @@ -41,14 +41,26 @@ public class LinkedList return result; } - public int erste(){ - int tmp = this.start.wert; + public T erste(){ + if ( this.start == null){ + return null; + } + + T tmp = this.start.wert; + this.start = this.start.next; return tmp; } - public int getNteZahl(int n){ - return 0; + public T getNteZahl(int n){ + Node current = this.start; + + for (int i = 0; i < n; i++){ + if (current == null) return null; + current = current.next; + } + if( current == null) return null; + return current.wert; } } diff --git a/Node.java b/Node.java index 7707fdd..957c4bf 100644 --- a/Node.java +++ b/Node.java @@ -1,10 +1,10 @@ -public class Node +public class Node { - public int wert; + public T wert; public Node next; - public void setWert(int w){ + public void setWert(T w){ this.wert = w; } public void setNext(Node n){ diff --git a/Test3.java b/Test3.java index 91e865e..74a5636 100644 --- a/Test3.java +++ b/Test3.java @@ -16,4 +16,13 @@ public class Test3 System.out.println(1); } + public static void test2(){ + Node n = new Node(); + + n.wert = "Hallo"; + + Node i = new Node(); + + i.wert = 5; + } }