-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueueUsingLinkedList.h
68 lines (53 loc) · 1.09 KB
/
QueueUsingLinkedList.h
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
struct Node{
int data;
struct Node *next;
};
struct Node *Front = NULL;
struct Node *Rear = NULL;
bool isEmpty(){
return (Front == NULL && Rear == NULL);
}
void Enqueue(int data){
struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
newNode -> data = data;
newNode -> next = NULL;
if(isEmpty()){
Front = Rear = newNode;
return;
}
Rear -> next = newNode;
Rear = newNode;
}
void Dequeue(){
if(Front == NULL)
return;
if(Front == Rear)
Front = Rear = NULL;
else{
struct Node *newNode = Front;
Front = Front -> next;
free(newNode);
}
}
int FrontIndex(){
return Front -> data;
}
void Print(){
struct Node *newNode = Front;
while(newNode != NULL){
printf("%d ",newNode -> data);
newNode = newNode -> next;
}
printf("\n");
}
bool Search(int data){
struct Node *newNode = Front;
while(newNode != NULL){
if(newNode -> data == data)
return true;
newNode = newNode -> next;
}
return false;
}
void Details(){
}