-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue Array.cpp
More file actions
84 lines (73 loc) · 1.06 KB
/
Queue Array.cpp
File metadata and controls
84 lines (73 loc) · 1.06 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
/* different opeartions on queue using array */
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 10
struct queue
{
int data [MAXSIZE];
int front,rear;
};
int main()
{
void insert(struct queue *,int );
int delete(struct queue *);
int empty(struct queue *);
struct queue q;
int x,n,elt;
char ch;
q.front=0;
q.rear=-1;
do
{
printf("MENU\n");
printf("1. Insert\n2. Delete\n3. Exit\n");
printf("enter the choice ");
scanf("%d",&n);
switch(n)
{
case 1:
printf("enter the no to be inserted ");
scanf("%d",&elt);
insert(&q,elt);
break;
case 2:
if(empty(&q))
printf("UNDERFLOW\n");
else
x=delete(&q);
printf("delete element = %d",x);
break;
case 3:
exit(0);
break;
}
}
while(n<4);
return(0);
}
int empty(struct queue *pq)
{
if(pq->rear<pq->front)
{
return(1);
}
else
{
return(0);
}
}
void insert(struct queue *pq,int x)
{
if(pq->rear==MAXSIZE-1)
{
printf("OVERFLOW\n");
}
else
{
pq->data[1+pq->rear]=x;
}
}
int delete(struct queue *pq)
{
return(pq->data[pq->front++]);
}