-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestStack.java
More file actions
45 lines (34 loc) · 1.12 KB
/
TestStack.java
File metadata and controls
45 lines (34 loc) · 1.12 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
package sjjg;
public class TestStack {
public static void main(String[] args) {
// TODO 自动生成的方法存根
//TestSeqStack
String[] values1 = {"A","B","C","D"};
SeqStack<String> list1 = new SeqStack<String>();
list1.push(values1[0]); //测试入栈
System.out.println(list1.toString());
list1.push(values1[2]);
System.out.println(list1.toString());
list1.push(values1[1]);
System.out.println(list1.toString());
System.out.println(list1.peek()); //测试返回栈顶元素
list1.pop(); //测试出栈
System.out.println(list1.toString());
list1.pop();
System.out.println(list1.toString());
System.out.println("\n");
//TestLinkedStack
LinkedStack<String> list2 = new LinkedStack<String>();
list2.push(values1[0]); //测试入栈
System.out.println(list2.toString());
list2.push(values1[2]);
System.out.println(list2.toString());
list2.push(values1[1]);
System.out.println(list2.toString());
System.out.println(list2.peek()); //测试返回栈顶元素
list2.pop(); //测试出栈
System.out.println(list2.toString());
list2.pop();
System.out.println(list2.toString());
}
}