-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstacks.java
38 lines (33 loc) · 827 Bytes
/
stacks.java
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
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
public class stacks {
public static void main(String[] args) {
Stack<Integer> stack = new Stack<>();// Directly make a stack
// push
stack.add(1);
// pop
stack.pop();
// empty
stack.size();
// front
stack.peek();
//queue
Queue<Integer> queue = new LinkedList<>();
queue.add(1);// Push
queue.peek(); // Front
queue.poll(); // poll
queue.size(); // Empty
// Priorrity Queue
PriorityQueue<Integer> pq = new PriorityQueue<>();
// push
pq.add(1);
// poll
pq.poll();
// empty
pq.size();
// first
pq.peek();
}
}