-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_.java
More file actions
31 lines (28 loc) · 821 Bytes
/
Stack_.java
File metadata and controls
31 lines (28 loc) · 821 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
package LeetCode_Java.Java_Basic;
import java.util.LinkedList;
import java.util.Stack;
public class Stack_ {
public static void main(String[] args) {
/*
peek()
add()
pop()
isEmpty()
*/
Stack<Integer> stack = new Stack<>();
stack.add(3);
stack.add(2);
stack.add(1);
while(!stack.isEmpty()){
System.out.println(stack.peek());
System.out.println(stack.pop());
}
LinkedList<Integer> stackLinkedList = new LinkedList<>();
stackLinkedList.add(3);
stackLinkedList.add(2);
stackLinkedList.add(1);
while(!stackLinkedList.isEmpty()){
System.out.println(stackLinkedList.removeLast()); //不能用pop,因为linkedlist的pop是首位
}
}
}