forked from Haresh1204/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDYNCQUEU.C
88 lines (88 loc) · 1.4 KB
/
DYNCQUEU.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
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
struct node
{
int info;
struct node *next;
}*rear=NULL,*front=NULL;
void main()
{
int ch;
clrscr();
while(1)
{
printf("\n1.Insert item");
printf("\n2.Delete item");
printf("\n3.Display");
printf("\n4.Quit");
printf("\nEnter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert_item();
break;
case 2:
del_item();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
printf("\n Wrong choice Try again");
}
}
}
insert_item()
{
struct node *temp;
int item;
temp=(struct node*)malloc(sizeof(struct node));
printf("\n Enter item to be inserted in the queue= ");
scanf("%d",&item);
temp->info=item;
if(front==NULL)
front=temp;
else
{
temp->next=front;
rear->next=temp;
}
rear=temp;
}
del_item()
{
struct node *temp;
if(front==NULL)
printf("\n Queue underflow");
else
{
temp=front;
printf("\nElement after deletion is=%d",temp->info);
front=front->next;
if(front==rear)
{
front=NULL;
rear=NULL;
}
free(temp);
}
}
display()
{
struct node *trav;
if(front==NULL)
printf("\n Cqueue is empty");
else
{
printf("\n contents of queue are= ");
for(trav=front;trav->next!=rear->next;trav=trav->next)
{
printf("%d",trav->info);
}
printf("%d",rear->info);
}
}