27. asar
parent
71feb001f7
commit
c0bdbe1d81
|
@ -1,4 +1,4 @@
|
||||||
import java.util.random
|
import java.util.Random;
|
||||||
|
|
||||||
public class Auto
|
public class Auto
|
||||||
{
|
{
|
||||||
|
|
28
List.java
28
List.java
|
@ -25,7 +25,8 @@ public class List<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
public T get(int n) {
|
public T get(int n) {
|
||||||
Node<T> current = first;
|
|
||||||
|
Node<T> current = first;
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
if (current == null) return null;
|
if (current == null) return null;
|
||||||
|
@ -65,7 +66,7 @@ public class List<T>
|
||||||
first = neu;
|
first = neu;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Node<T> current = first;
|
||||||
for (int i = 0; i < n-1; i++){
|
for (int i = 0; i < n-1; i++){
|
||||||
current = current.next;
|
current = current.next;
|
||||||
}
|
}
|
||||||
|
@ -85,6 +86,29 @@ public class List<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
public T remove(int n) {
|
public T remove(int n) {
|
||||||
|
if (n >= size()) return null;
|
||||||
|
if (n == 0) {
|
||||||
|
T tmp = first.wert;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
Node<T> 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<T> current = first;
|
||||||
|
while (current != null) {
|
||||||
|
result += current.wert + ", ";
|
||||||
|
current = current.next;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
public class Node<T>
|
public class Node<T>
|
||||||
{
|
{
|
||||||
public T wert;
|
public T wert;
|
||||||
public Node next;
|
public Node<T> next;
|
||||||
|
|
||||||
public void setWert(T w){
|
public void setWert(T w){
|
||||||
this.wert = w;
|
this.wert = w;
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
public class Queue<T>
|
||||||
|
{
|
||||||
|
private Node<T> first;
|
||||||
|
|
||||||
|
public Queue() {
|
||||||
|
first = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
if (first == null) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public T front(int n) {
|
||||||
|
|
||||||
|
Node<T> 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<T> neu = new Node<T>();
|
||||||
|
neu.wert = val;
|
||||||
|
|
||||||
|
if (first == null) {
|
||||||
|
first = neu;
|
||||||
|
} else {
|
||||||
|
Node<T> 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<T> current = first;
|
||||||
|
while (current != null) {
|
||||||
|
result += current.wert + ", ";
|
||||||
|
current = current.next;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,14 +17,14 @@ public class Rennen
|
||||||
|
|
||||||
}
|
}
|
||||||
public void lasseSchneckenKriechen(){
|
public void lasseSchneckenKriechen(){
|
||||||
this.teilnehmer1.krieche();
|
this.teilnehmer1.krieche(1);
|
||||||
this.teilnehmer3.krieche();
|
this.teilnehmer3.krieche(1);
|
||||||
this.teilnehmer2.krieche();
|
this.teilnehmer2.krieche(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
public Rennschnecke durchfuehren(){
|
public Rennschnecke durchfuehren(){
|
||||||
while(true){
|
while(true){
|
||||||
this.lasseSchneckenKriechen;
|
this.lasseSchneckenKriechen();
|
||||||
if(this.teilnehmer1.getStrecke() > this.distanz) {
|
if(this.teilnehmer1.getStrecke() > this.distanz) {
|
||||||
return this.teilnehmer1;
|
return this.teilnehmer1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,10 @@ public class Rennschnecke
|
||||||
this.max = max;
|
this.max = max;
|
||||||
this.weg = weg;
|
this.weg = weg;
|
||||||
}
|
}
|
||||||
|
public double getStrecke()
|
||||||
|
{
|
||||||
|
return weg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
|
||||||
|
|
||||||
|
public class Stack
|
||||||
|
{ private Node<T> first;
|
||||||
|
|
||||||
|
public List() {
|
||||||
|
first = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
if (first == null) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
Node<T> current = first;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
while (current != null) {
|
||||||
|
count++;
|
||||||
|
current = current.next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(int n) {
|
||||||
|
|
||||||
|
Node<T> 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<T> neu = new Node<T>();
|
||||||
|
neu.wert = val;
|
||||||
|
|
||||||
|
if (first == null) {
|
||||||
|
first = neu;
|
||||||
|
} else {
|
||||||
|
Node<T> 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<T> neu = new Node<T>();
|
||||||
|
|
||||||
|
neu.wert = val;
|
||||||
|
|
||||||
|
if (n==0){
|
||||||
|
neu.next = first;
|
||||||
|
first = neu;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Node<T> 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<T> 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<T> current = first;
|
||||||
|
while (current != null) {
|
||||||
|
result += current.wert + ", ";
|
||||||
|
current = current.next;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue