-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue using array.c
85 lines (78 loc) · 1 KB
/
queue using array.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
#include<stdio.h>
#define MAXSIZE 4
int q[MAXSIZE];
void menu();
void enqueue();
void dequeue();
void show();
int rear=-1;
int front=-1;
int main()
{
while(1)
menu();
}
void menu()
{
int ch;
printf("\n menu \n1 enqueue \n2 dequeue \n3 show \n4 exit");
scanf("%d",&ch);
switch(ch)
{
case 1: enqueue();
break ;
case 2: dequeue();
break ;
case 3: show();
break ;
case 4: exit(1);
break ;
default : printf("\nwrong input");
}
}
void enqueue()
{
int item ;
if( rear==MAXSIZE-1)
{
printf("\nqueue is full");
}
else
{
rear=rear+1;
printf("\n enter the number");
scanf("%d",&item);
q[rear]=item;
if(front=-1)
{
front=front+1;
}
}
}
void dequeue()
{
if (front==-1)
{
printf("\nqueue is empty");
}
else if(front == rear)
front=rear=-1;
else
{
printf("\n %d dequeue from the queue",q[front]);
front=front+1;
}
}
void show()
{
int i;
if (front==-1)
{
printf("\nqueue is empty");
}
else
for(i=front;i<=rear;i++)
{
printf("\n %d",q[i]);
}
}