1
2
3
4
5
6
7
8
9
10
11
12
13public
14class Stack2
15extends java.util.Vector
16implements StackInterface {
17
18
19
20
21
22 public
23 Stack2() {
24 super();
25 }
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public
41 Object top()
42 {
43 assert preTop() : "Stack2.top: empty stack";
44
45 return
46 lastElement();
47 }
48
49
50
51 public
52 void push(Object o) {
53 addElement(o);
54 }
55
56
57
58 public
59 void pop()
60 {
61 assert prePop() : "Stack2.pop: empty stack";
62
63 removeElementAt(elementCount-1);
64 }
65
66
67
68
69
70
71 public
72 boolean prePop() {
73 return
74 ! isEmpty();
75 }
76
77 public
78 boolean preTop() {
79 return
80 ! isEmpty();
81 }
82
83}
84
85