-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueueArray.c
68 lines (66 loc) · 1.12 KB
/
QueueArray.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
#include<stdio.h>
#include<stdlib.h>
#define maxsize 5
int front=-1,rear=-1;
int queue[maxsize];
void insert(int item)
{
if(rear== maxsize-1){
printf("\n Cannot add element");
return;
}
if(front==-1 && rear==-1)
{
front=0;
rear=0;
}
else{
rear=rear+1;
}
queue[rear]=item;
printf("\n element inserted");
}
void delete(){
int item;
if(front==-1 || front>rear){
printf("\n Underflow");
return;
}
else{
item=queue[front];
if(front==rear){
front=-1;
rear=-1;
}
else{
front=front+1;
}
printf("\n value deleted");
}
}
void display(){
int i;
if(rear==-1){
printf("\n empty queue");
}
else{
printf("\n printing values ....\n");
for(i=front;i<=rear;i++){
printf("\n%d\n",queue[i]);
}
}
}
int main()
{
insert(11);
insert(12);
insert(13);
insert(14);
insert(15);
display();
delete();
delete();
delete();
display();
return 0;
}