forked from R0HITKUMAR/webDevUsingGSheets.sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueueUsingLinkedList.c
More file actions
68 lines (65 loc) · 1.45 KB
/
queueUsingLinkedList.c
File metadata and controls
68 lines (65 loc) · 1.45 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
// Queue Using Linked List
#include<stdio.h>
#include<stdlib.h>
#include "linkedList.h"
Empty(struct node **REAR,struct node **FRONT)
{
if ((*FRONT)==NULL &&(*REAR)==NULL)
{
return 1;
}
else
{
return 0;
}
}
Enqueue(struct node **REAR,struct node **FRONT,int x)
{
if (REAR==NULL)
{
InsBeg(&(*REAR),x);
FRONT = REAR;
}
InsAFT(&(*REAR),x);
(*REAR)=(*REAR)->next;
}
int Dequeue(struct node **REAR,struct node **FRONT)
{
int x;
if ((*FRONT) == NULL)
{
printf("Queue Underflows");
exit(1);
}
x = DelBeg(&(*FRONT));
if ((*FRONT)==NULL)
REAR = NULL;
return x;
}
int main()
{
struct node *FRONT,*REAR;
int x;
FRONT = NULL;
REAR = NULL;
Enqueue(&REAR,&FRONT,100);
Enqueue(&REAR,&FRONT,200);
Enqueue(&REAR,&FRONT,300);
Enqueue(&REAR,&FRONT,400);
Enqueue(&REAR,&FRONT,500);
Enqueue(&REAR,&FRONT,600);
x = Dequeue(&REAR,&FRONT);
printf("\nDeleted Item = %d",x);
x = Dequeue(&REAR,&FRONT);
printf("\nDeleted Item = %d",x);
x = Dequeue(&REAR,&FRONT);
printf("\nDeleted Item = %d",x);
x = Dequeue(&REAR,&FRONT);
printf("\nDeleted Item = %d",x);
x = Dequeue(&REAR,&FRONT);
printf("\nDeleted Item = %d",x);
x = Dequeue(&REAR,&FRONT);
printf("\nDeleted Item = %d\n",x);
x = Dequeue(&REAR,&FRONT);
return 0;
}