-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLQueue.java
More file actions
64 lines (50 loc) · 1.08 KB
/
Copy pathLQueue.java
File metadata and controls
64 lines (50 loc) · 1.08 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
/*Create a queue using the basic memory pointers and which stores LeftHeapNode */
/*Structure for a queue */
public class LQueue {
ListNode front;
ListNode rear;
public LQueue() {
this.front=this.rear=null;
}
/*checks if Queue is Empty*/
public boolean isQueueEmpty() {
return(this.front==null);
}
//Enqueue operation
public void enQueue(LeftHeapNode data) {
ListNode newNode = new ListNode(data);
if(rear==null) {
rear=newNode;
}
else {
this.rear.next=newNode;
this.rear = newNode;
}
if(this.front==null) {
this.front=this.rear;
}
}
//dequeue from queue
public LeftHeapNode deQueue() {
if(isQueueEmpty())
return null;
else {
ListNode temp = this.front;
LeftHeapNode data = this.front.node;
this.front=this.front.next;
temp=null;
return data;
}
}
//deletes the queue
public void deleteQueue() {
if(this!=null) {
ListNode current=this.front;
while(current!=null) {
ListNode temp = current;
current=current.next;
temp=null;
}
}
}
}