-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQueue-Using-Array.c
More file actions
81 lines (71 loc) · 1.04 KB
/
Queue-Using-Array.c
File metadata and controls
81 lines (71 loc) · 1.04 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
#include<stdio.h>
int n;
int front=-1,rear=-1;
void insert(int,int*,int*,int*);
void delete(int*,int*,int*);
void display(int*);
void main()
{
int d;
printf("Enter the size of queue");
scanf("%d",&n);
int arr[n];
while(1)
{
int c;
printf("Enter 1 for Insert\nEnter 2 for delete\nEnter 3 for display\n");
scanf("%d",&c);
switch(c)
{
case 1: printf("Enter the number which you want to add\n");
scanf("%d",&d);
insert(d,arr,&front,&rear);
break;
case 2: delete(arr,&front,&rear);
break;
case 3: display(arr);
break;
default:printf("Enter correct number\n");
}
}
}
void insert(int data,int*a,int*f,int*r)
{
if(*r==n-1)
{
printf("queue is full\n");
}
else
{
(*r)++;
a[*r]=data;
}
if(*f=-1)
{
*f=0;
}
}
void delete(int*a,int*f,int*r)
{
if(*r==-1)
{
printf("queue is empty\n");
}
int temp=a[*f];
a[*f]=0;
if(*f==*r)
{
*f=-1;
*r=-1;
}
else
{
(*f)++;
}
printf("%d is deleted\n",temp);
}
void display(int*a)
{
for(int i=front;i<=rear;i++)
printf("---->%d ",a[i]);
}