-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinInStack.java
More file actions
53 lines (40 loc) · 1.18 KB
/
Copy pathMinInStack.java
File metadata and controls
53 lines (40 loc) · 1.18 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
package minInStack;
import org.junit.Test;
/**
* 包含min函数的栈
* 题目:定义栈的数据结构,请在该类型中实现一个能够得到栈的最小元素的min
* 函数。在该栈中,调用min、push及pop的时间复杂度都是O(1)。
* Created by hxchen on 2018/6/26.
*/
public class MinInStack {
public void Test(String name, StackWithMin<Integer> stack, int expected) {
if (name != null) {
System.out.format("%s starts,", name);
}
if (stack.min() == expected) {
System.out.println("Passed.");
} else {
System.out.println("Failed.");
}
}
@Test
public void test1() {
StackWithMin<Integer> stack = new StackWithMin<>();
stack.push(3);
Test("Test1", stack, 3);
stack.push(4);
Test("Test2", stack, 3);
stack.push(2);
Test("Test3", stack, 2);
stack.push(3);
Test("Test4", stack, 2);
stack.pop();
Test("Test5", stack, 2);
stack.pop();
Test("Test6", stack, 3);
stack.pop();
Test("Test7", stack, 3);
stack.push(0);
Test("Test8", stack, 0);
}
}