-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathQueueUsingStackDequeueEff.java
More file actions
58 lines (47 loc) · 1.06 KB
/
QueueUsingStackDequeueEff.java
File metadata and controls
58 lines (47 loc) · 1.06 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
54
55
56
57
58
package lecture9a15;
import lecture9a13.Stack;
public class QueueUsingStackDequeueEff {
Stack s = new DynamicStack();
public void enqueue(int item) throws Exception {
try {
Stack temp = new DynamicStack();
while (!s.isEmpty()) {
temp.push(s.pop());
}
s.push(item);
while (!temp.isEmpty()) {
s.push(temp.pop());
}
} catch (Exception e) {
throw new Exception("Queue is Full");
}
}
public int dequeue() throws Exception {
try {
return s.pop();
} catch (Exception e) {
throw new Exception("Queue is Full");
}
}
public void display() throws Exception {
try { s.display();
}catch (Exception e) {
throw new Exception("Queue is Empty");
}
}
public int front() throws Exception {
try { return s.peek();
}catch (Exception e) {
throw new Exception("Queue is Empty");
}
}
public boolean isEmpty() throws Exception {
return s.isEmpty();
}
public boolean isFull() throws Exception {
return s.isFull();
}
public int size (){
return s.size();
}
}