-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchlange.java
More file actions
60 lines (57 loc) · 1.39 KB
/
Schlange.java
File metadata and controls
60 lines (57 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public class Schlange implements Functions{
private Element erstes;
private Element letztes;
private class Element{
public int wert;
public Element naechstes;
public Element(int wert){
this.wert = wert;
}
}
public void einfuegen(int wert){
Element neu = new Element(wert);
if(letztes == null){
erstes = neu;
letztes = neu;
} else {
letztes.naechstes = neu;
letztes = neu;
}
}
public int entfernen(){
int out_wert = 0;
if(erstes == letztes){
erstes = null;
letztes = null;
} else {
out_wert = erstes.wert;
erstes = erstes.naechstes;
}
return out_wert;
}
public String ausgeben(){
String output = "";
Element akt = erstes;
while(akt != null){
output += Integer.toString(akt.wert);
if(akt.naechstes != null){
output += "->";
}
akt = akt.naechstes;
}
if(output == ""){
return "-- leer --";
} else {
return output;
}
}
public int gibLaenge(){
int laenge = 0;
Element akt = erstes;
while(akt != null){
laenge++;
akt = akt.naechstes;
}
return laenge;
}
}