-
Notifications
You must be signed in to change notification settings - Fork 21
/
QueuesuingLL.java
54 lines (47 loc) · 996 Bytes
/
QueuesuingLL.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
53
54
public class QueueusingLL<T>{
private Node<T> front;
private Node<T> rear;
private int size;
public QueueusingLL() {
front = null;
rear = null;
size =0;
}
int size(){
return size;
}
boolean isEmpty(){
return (size==0);
}
T front(){
if (size==0){
System.out.println("Queue is Empty");
}
return front.data;
}
void enqueue(T input){
Node<T> temp = new Node<>(input);
if (size==0){
front = temp;
rear = temp;
size++;
}else{
rear.next = temp;
rear = rear.next;
rear.next = null;
size++;
}
}
T dequeue() {
if (size==0){
System.out.println("Queue is Empty");
}
T temp = front.data;
front = front.next;
if (size==1){
rear = null;
}
size--;
return temp;
}
}