14 Asar
parent
914ded100b
commit
c7332a559c
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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){
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue