-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueueUsingLL.java
52 lines (46 loc) · 1.08 KB
/
QueueUsingLL.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class QueueNode{
public QueueNode next;
public int data;
public QueueNode(int key) {
this.data = key;
this.next = null;
}
}
class test {
QueueNode front, rear;
public test() {
this.front = this.rear = null;
}
void enQueue(int key){
QueueNode temp = new QueueNode(key);
if(this.rear == null){
this.front = this.rear = temp;
return;
}
this.rear.next = temp;
this.rear = temp;
}
void deQueue(){
if(this.front == null){
return;
}
// QueueNode temp = this.front;
this.front = this.front.next;
if(this.front == null){
this.rear = null;
}
}
}
public class QueueUsingLL{
public static void main(String[] args) {
test q = new test();
q.enQueue(10);
q.enQueue(11);
q.enQueue(12);
System.out.println(q.front.data+ " "+q.rear.data);
q.deQueue();
q.deQueue();
q.deQueue();
System.out.println(q.front.data+ " "+q.rear.data);
}
}