-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStack.java
More file actions
37 lines (30 loc) · 747 Bytes
/
Copy pathStack.java
File metadata and controls
37 lines (30 loc) · 747 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
package com.owl.algorithm.stack;
import com.owl.algorithm.vector.Vector;
/**
* 通过继承向量,实现栈
*/
public class Stack<T extends Comparable<T>> extends Vector<T> {
public Stack() {
super();
}
public Stack(int _capacity) {
super(_capacity);
}
public void push(T data) {
this.insert(size(), data);
}
public T pop() {
return remove(size() - 1);
}
public T top() {
return get(size() - 1);
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < size(); i++) {
buffer.append("(").append(get(i)).append(")").append("-");
}
return buffer + ">";
}
}