diff --git a/Auto.java b/Auto.java index 8659f61..65740ad 100644 --- a/Auto.java +++ b/Auto.java @@ -1,4 +1,4 @@ -import java.util.random +import java.util.Random; public class Auto { diff --git a/List.java b/List.java index 23c144b..5052117 100644 --- a/List.java +++ b/List.java @@ -25,7 +25,8 @@ public class List } public T get(int n) { - Node current = first; + + Node current = first; for (int i = 0; i < n; i++) { if (current == null) return null; @@ -65,7 +66,7 @@ public class List first = neu; return; } - + Node current = first; for (int i = 0; i < n-1; i++){ current = current.next; } @@ -85,6 +86,29 @@ public class List } public T remove(int n) { + if (n >= size()) return null; + if (n == 0) { + T tmp = first.wert; + return tmp; + } + Node current = first; + + for (int i = 0; i< n-1; i++) + { + current = current.next; + } + T tmp = current.next.wert; + current.next = current.next.next; + return tmp; } + public String toString(){ + String result = ""; + Node current = first; + while (current != null) { + result += current.wert + ", "; + current = current.next; + } + return result; + } } diff --git a/Node.java b/Node.java index 957c4bf..90ddc17 100644 --- a/Node.java +++ b/Node.java @@ -2,7 +2,7 @@ public class Node { public T wert; - public Node next; + public Node next; public void setWert(T w){ this.wert = w; diff --git a/Queue.java b/Queue.java new file mode 100644 index 0000000..decdded --- /dev/null +++ b/Queue.java @@ -0,0 +1,65 @@ +public class Queue +{ + private Node first; + + public Queue() { + first = null; + } + + public boolean isEmpty() { + if (first == null) return true; + return false; + } + + + + public T front(int n) { + + Node current = first; + + for (int i = 0; i < n; i++) { + if (current == null) return null; + current = current.next; + } + + if (current == null) return null; + return current.wert; + } + + public void enqueue(T val) { + Node neu = new Node(); + neu.wert = val; + + if (first == null) { + first = neu; + } else { + Node current = first; + while (current.next != null) { + current = current.next; + } + current.next = neu; + } + } + + + + + + public T dequeue() { + T tmp = first.wert; + first = first.next; + return tmp; + + } + + public String toString(){ + String result = ""; + Node current = first; + while (current != null) { + result += current.wert + ", "; + current = current.next; + } + return result; + } +} + diff --git a/Rennen.java b/Rennen.java index 9bc79dc..a60be3e 100644 --- a/Rennen.java +++ b/Rennen.java @@ -17,14 +17,14 @@ public class Rennen } public void lasseSchneckenKriechen(){ - this.teilnehmer1.krieche(); - this.teilnehmer3.krieche(); - this.teilnehmer2.krieche(); + this.teilnehmer1.krieche(1); + this.teilnehmer3.krieche(1); + this.teilnehmer2.krieche(1); } public Rennschnecke durchfuehren(){ while(true){ - this.lasseSchneckenKriechen; + this.lasseSchneckenKriechen(); if(this.teilnehmer1.getStrecke() > this.distanz) { return this.teilnehmer1; } diff --git a/Rennschnecke.java b/Rennschnecke.java index c22d147..8af864a 100644 --- a/Rennschnecke.java +++ b/Rennschnecke.java @@ -15,7 +15,10 @@ public class Rennschnecke this.max = max; this.weg = weg; } - + public double getStrecke() + { + return weg; + } } diff --git a/Stack.java b/Stack.java new file mode 100644 index 0000000..7d1ccdb --- /dev/null +++ b/Stack.java @@ -0,0 +1,105 @@ + + +public class Stack +{ private Node first; + + public List() { + first = null; + } + + public boolean isEmpty() { + if (first == null) return true; + return false; + } + + public int size() { + Node current = first; + int count = 0; + + while (current != null) { + count++; + current = current.next; + } + + return count; + } + + public T get(int n) { + + Node current = first; + + for (int i = 0; i < n; i++) { + if (current == null) return null; + current = current.next; + } + + if (current == null) return null; + return current.wert; + } + + public void add(T val) { + Node neu = new Node(); + neu.wert = val; + + if (first == null) { + first = neu; + } else { + Node current = first; + while (current.next != null) { + current = current.next; + } + current.next = neu; + } + } + + public void add(int n, T val) { + if (n >=size()) { + add(val); + return; + } + Node neu = new Node(); + + neu.wert = val; + + if (n==0){ + neu.next = first; + first = neu; + return; + } + Node current = first; + for (int i = 0; i < n-1; i++){ + current = current.next; + } + neu.next = current.next; + current.next = neu; + + } + + public boolean contains(T val) { + Node current = first; + + while (current != null) { + if (current.wert.equals(val)) return true; + } + + return false; + } + + public T pull(int n) { + + T tmp = first.wert; + first = first.next; + + return tmp; + + } + public String toString(){ + String result = ""; + Node current = first; + while (current != null) { + result += current.wert + ", "; + current = current.next; + } + return result; + } +}