diff --git a/LinkedList.java b/LinkedList.java new file mode 100644 index 0000000..9295b78 --- /dev/null +++ b/LinkedList.java @@ -0,0 +1,54 @@ + +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; + } + +} diff --git a/Node.java b/Node.java new file mode 100644 index 0000000..7707fdd --- /dev/null +++ b/Node.java @@ -0,0 +1,13 @@ + +public class Node +{ + public int wert; + public Node next; + + public void setWert(int w){ + this.wert = w; + } + public void setNext(Node n){ + this.next = n; + } +} diff --git a/Test2.java b/Test2.java new file mode 100644 index 0000000..bc84eda --- /dev/null +++ b/Test2.java @@ -0,0 +1,22 @@ + +public class Test2 +{ + public static Node test() { + Node n1 = new Node(); + n1.setWert(3); + + Node n2 = new Node(); + n2.setWert(7); + n1.setNext(n2); + + Node n3 = new Node(); + n3.setWert(11); + n2.setNext(n3); + + Node n4 = new Node(); + n4.setWert(12);n3.setNext(n4); + + return n1; + } + } + diff --git a/Test3.java b/Test3.java new file mode 100644 index 0000000..91e865e --- /dev/null +++ b/Test3.java @@ -0,0 +1,19 @@ + +public class Test3 +{ + public static void test(){ + LinkedList l = new LinkedList(); + + l.einfuegen(4); + l.einfuegen(8); + l.einfuegen(3); + l.einfuegen(17); + + System.out.println(l); + System.out.println(l.erste() ); + + + System.out.println(1); + + } +}