-
Notifications
You must be signed in to change notification settings - Fork 1
/
LL Que.c
95 lines (83 loc) · 1.42 KB
/
LL Que.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<stdio.h>
#define pf printf
#define sf scanf
struct {
int data;
struct node *next;
};node
struct node *front,*end;
void enqueue ();
void dequeue ();
void display ();
void main ()
{
int ch;
front=end=NULL;
do{
pf("1:enq\n2:deq\n3:dis\n4:exit\nchoice:");
sf("%d",&ch);
switch(ch)
{
case 1:enqueue();break;
case 2:dequeue();break;
case 3:display();break;
case 4:pf("\nProgram End\n");break;
default:pf("\nWrong choice\n");break;
}
}while(ch!=4);
}
void enqueue ()
{
struct node *nn;
nn=(struct node *) malloc(sizeof (struct node));
pf("\n\nenter data\n\n");
sf("%d",&nn->data);
nn->next=NULL;
if(end==NULL)
{
front=nn;
end=nn;
}
else
{
end->next=nn;
end=nn;
}
pf("\n\n%d is enqued\n\n",nn->data);
}
void dequeue()
{ struct node *p;
int x;
if(end==NULL)
{
pf("\n\nque is empty\n\n");
return;
}
p=front;
x=front->data;
if(front==end)
{
front=end=NULL;
}
else
{
front=front->next;
}
free(p);
pf("\n\n%d is dequed\n\n",x);
}
void display()
{
struct node *p;
if(front==NULL)
{
pf("Que is empty");
return;
}
p=front;
while(p!=NULL)
{
pf("\n%d\n",p->data);
p=p->next;
}
}