-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathqueue_LL.c
More file actions
98 lines (96 loc) · 1.6 KB
/
queue_LL.c
File metadata and controls
98 lines (96 loc) · 1.6 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
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
96
97
98
#include<stdio.h>
typedef struct list
{
int info;
struct list *next;
}NODE;
void insert(NODE **pfront,NODE **prear,int n)
{
NODE *node;
node=(NODE *)malloc(sizeof(NODE));
if(node==NULL)
{
printf("Queue Overflow");
return;
}
node->info=n;
node->next=NULL;
if(*pfront==NULL)
{
*pfront=*prear=node;
}
else
{
(*prear)->next=node;
(*prear)=(*prear)->next;
}
}
int delete(NODE **pfront,NODE **prear)
{
int n=0;
NODE *temp;
if(*pfront==NULL)
{
printf("\nQueue Underflow");
}
else
{
n=(*pfront)->info;
if(*pfront==*prear)
{
free(*pfront);
*pfront=*prear=NULL;
}
else
{
temp=*pfront;
(*pfront)=(*pfront)->next;
free(temp);
}
}
return n;
}
void traverse(NODE *front)
{
NODE *p=front;
if(p==NULL)
{
printf("\nQueue Underflow");
return;
}
while(p!=NULL)
{
printf("%5d",p->info);
p=p->next;
}
}
int main()
{
NODE *front=NULL,*rear=NULL;
int n,ch;
do{
printf("\n*****MENU*****");
printf("\n1. Insert");
printf("\n2. Delete");
printf("\n3. traverse");
printf("\n4. Exit");
printf("\n***************");
printf("\nEnter Your Choice 1/2/3/4 : ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nEnter value to insert : ");
scanf("%d",&n);
insert(&front,&rear,n);
break;
case 2: n=delete(&front,&rear);
printf("\n%d deleted",n);
break;
case 3: traverse(front);
break;
case 4: printf("\n\n Thank you");
break;
default:printf("\nWrong Choice....");
}
}while(ch!=4);
}