-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue Link.cpp
More file actions
103 lines (92 loc) · 1.38 KB
/
Queue Link.cpp
File metadata and controls
103 lines (92 loc) · 1.38 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
99
100
101
/* different opeartions using linked list */
#include<stdio.h>
#include<stdlib.h>
struct queue
{
int data;
struct queue *next;
};
int main()
{
int n,choice;
struct queue *front,*rear;
int empty(struct queue *);
int delete(struct queue **,struct queue **);
void insert(struct queue **,struct queue **,int );
front=rear=NULL;
while(1)
{
printf("MENU\n");
printf("1. Insert\n2. Delete\n3. Exit\n");
printf("enter the choice ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("enter the no to be inserted ");
scanf("%d",&n);
insert(&front,&rear,n);
break;
case 2:
if(empty(front))
{
printf("UNDERFLOW\n");
}
else
{
printf("front element = %d\n",delete(&front,&rear));
}
break;
case 3:
exit(0);
break;
}
}
return(0);
}
void insert(struct queue **front,struct queue **rear,int x)
{
struct queue *p;
p=(struct queue *)malloc(sizeof(struct queue));
if (p==NULL)
{
printf("OVERFLOW\n");
}
else
{
p->data=x;
p->next=NULL;
if(*rear==NULL)
{
*front=p;
}
else
{
(*rear)->next=p;
*rear=p;
}
}
}
int empty(struct queue *front)
{
if(front==NULL)
{
return(1);
}
else
{
return(0);
}
}
int delete(struct queue **front,struct queue **rear)
{
struct queue *p;
int x;
p=*front;
x=p->data;
*front=(*front)->next;
if(*front==NULL)
*rear=NULL;
free(p);
return(x);
}