-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueuelinked.c
94 lines (93 loc) · 1.17 KB
/
queuelinked.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
#include<stdio.h>
#include<stdlib.h>
#define size 25
struct NODE
{
int info;
struct NODE *link;
};
typedef struct NODE node;
node *rear=NULL;
node *front=NULL;
node *newnode(int elem)
{
node *p;
p=(node*)malloc(sizeof(node));
p->info=elem;
p->link=NULL;
return p;
}
void Insertqueue(int elem)
{
node *p;
p=newnode(elem);
p->info=elem;
p->link=NULL;
if(front==NULL)
front=rear=p;
else
{
rear->link=p;
rear=p;
}
}
void Deletequeue()
{
node *val;
val=front;
if(val==NULL)
printf("Queueis empty ");
else
{
val=front;
front=front->link;
free(val);
}
}
void Display()
{
node *curr;
curr=front;
while(curr!=NULL)
{
printf("%d ",curr->info);
curr=curr->link;
while(curr!=NULL)
break;
}
}
void main()
{
int ch,value;
do
{
printf("\n1. Insert\n2. Delete\n3. DISPLAY\n4. EXIT\n");
printf("Enter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("Value to be inserted ");
scanf("%d",&value);
Insertqueue(value);
break;
}
case 2:
{
Deletequeue();
break;
}
case 3:
{
Display();
break;
}
case 4:
break;
default :
printf("Invalid choice ");
}
}
while(ch!=4);
}