forked from girijamanoj/Basic-Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqueueStack.java
More file actions
74 lines (67 loc) · 1.14 KB
/
Copy pathqueueStack.java
File metadata and controls
74 lines (67 loc) · 1.14 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.*;
class Node {
int data;
Node next;
Node(int data) {
this.data = data;
this.next = null;
}
}
class Queue {
Stack S1 = new Stack;
Stack S2 = new Stack;
Node head;
Queue() {
this.head = null;
}
public void pop (int data) {
Node temp;
Node newNode = new Node(data);
if(top == null) {
top = newNode;
} else {
newNode.next = top;
top = newNode;
}
}
public void pop() {
Node temp;
if(top == null) {
System.out.println("Invalid");
}
else {
for(temp = top;temp.next != null;temp = temp.next);
top = top.next;
temp.next = null;
}
}
public void Isempty() {
if(head == null)
{
System.out.println("List is empty");
}
}
public enQueue (int data){
S1.push(data);
}
}
public int deQueue() {
if(S2 .Isempty()) {
while(!S1.Isempty()) {
S2.push(S1.pop);
return S1.pop;
}
}
public void print() {
}
public class queueStack {
public static void main(String[] args) {
Queue Q = new Queue();
Q.enQueue(1);
Q.enQueue(2);
Q.enQueue(3);
Q.deQueue();
Q.deQueue();
Q.print()
}
}