- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertexStack.java
More file actions
Latest commit
57 lines (43 loc) · 844 Bytes
/
Copy pathVertexStack.java
File metadata and controls
57 lines (43 loc) · 844 Bytes
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
importjava.util.EmptyStackException;
publicclassVertexStack { // stack for our paths so that we can find them
privateNodehead;
privateNodetop;
publicVertexStack() {
head=null;
}
privateclassNode{ // inner int node class
privateintindex;
protectedNodenext;
publicNode(intn) {
this.setIndex(n);
}
publicvoidsetIndex(intindex) {
this.index = index;
}
}
publicvoidpush(intind) {
Nodetemp=head;
head=newNode(ind);
head.next=temp;
}
publicintpop() throwsEmptyStackException{
inttemp;
if(head!=null) {
temp=head.index;
head=head.next;
}
else {
thrownewEmptyStackException();
}
returntemp;
}
publicbooleanisEmpty() {
returnhead==null;
}
publicNodegetTop() {
returntop;
}
publicvoidsetTop(Nodetop) {
this.top = top;
}
}