- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
Latest commit
83 lines (63 loc) · 1.42 KB
/
Copy pathQueue.java
File metadata and controls
83 lines (63 loc) · 1.42 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
packagellqueue;
importexceptions.PilhaVaziaException;
publicclassQueue {
// estou usando sentinelas!
privateNodestart;
privateNodeend;
publicQueue() {
end = newNode();
start = newNode(end);
}
publicvoidmimDaAFilaMano() {
Nodeactual = getStart().getNext();
System.out.printf("[ ");
while (actual!=end) {
if (actual.getNext() == end) System.out.printf("%s ", actual); elseSystem.out.printf("%s, ", actual);
actual = actual.getNext();
}
System.out.printf("], size: %d, isEmpty: %b %n", size(), isEmpty());
}
publicvoidenqueue(Objectvalue) {
Nodex = newNode();
x.setValue(value);
Nodey = start;
while (y.getNext() != end) {
y = y.getNext();
}
y.setNext(x);
x.setNext(end);
}
publicNodedequeue() {
if (start.getNext() == end) thrownewPilhaVaziaException("a pilha tá vazia, bicho");
Nodejudas = start.getNext();
start.setNext(judas.getNext());
returnjudas;
}
publicNodefirst() {
returnstart.getNext();
}
publicintsize() {
intsize = 0;
Nodeactual = start.getNext();
while(actual != end) {
size++;
actual = actual.getNext();
}
returnsize;
}
publicbooleanisEmpty() {
return (start.getNext() == end);
}
publicNodegetStart() {
returnstart;
}
publicvoidsetStart(Nodestart) {
this.start = start;
}
publicNodegetEnd() {
returnend;
}
publicvoidsetEnd(Nodeend) {
this.end = end;
}
}