master
Minkra 2023-12-05 12:02:43 +01:00
parent 914ded100b
commit c7332a559c
3 changed files with 31 additions and 10 deletions

View File

@ -1,12 +1,12 @@
public class LinkedList public class LinkedList<T>
{ {
private Node start; private Node<T> start;
public LinkedList(){ public LinkedList(){
} }
public void einfuegen(int zahl){ public void einfuegen(T zahl){
Node neu = new Node(); Node neu = new Node();
neu.wert = zahl; neu.wert = zahl;
if (this.start == null) { if (this.start == null) {
@ -41,14 +41,26 @@ public class LinkedList
return result; return result;
} }
public int erste(){ public T erste(){
int tmp = this.start.wert; if ( this.start == null){
return null;
}
T tmp = this.start.wert;
this.start = this.start.next; this.start = this.start.next;
return tmp; return tmp;
} }
public int getNteZahl(int n){ public T getNteZahl(int n){
return 0; Node<T> 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;
} }
} }

View File

@ -1,10 +1,10 @@
public class Node public class Node<T>
{ {
public int wert; public T wert;
public Node next; public Node next;
public void setWert(int w){ public void setWert(T w){
this.wert = w; this.wert = w;
} }
public void setNext(Node n){ public void setNext(Node n){

View File

@ -16,4 +16,13 @@ public class Test3
System.out.println(1); System.out.println(1);
} }
public static void test2(){
Node<String> n = new Node<String>();
n.wert = "Hallo";
Node<Integer> i = new Node<Integer>();
i.wert = 5;
}
} }