-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQueue using array.c
More file actions
68 lines (66 loc) · 1.22 KB
/
Copy pathQueue using array.c
File metadata and controls
68 lines (66 loc) · 1.22 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
// FIFO (Insert at end and deletion at beg)
#include<stdio.h>
#include<stdlib.h>
#define SIZE 50
int front= -1,rear =-1,queue[SIZE],item;
//insert
void insert()
{
if(rear == SIZE-1)
printf("OVERFLOW");
else
{
printf("Enter data\t:");
scanf("%d",&item);
if(front ==-1 && rear == -1) // IMP!
{
front = rear = 0;
queue[rear] = item;
}
else
queue[++rear] = item;
}
}
//delete
void delete()
{
if(front == -1 || front > rear)
{
printf("Queue is empty");
}
else
{
printf("Deleted item is %d \n",queue[front++]);
}
}
//display
void display()
{
int i;
printf("\n");
for(i = front; i <= rear; i++)
printf("%d\t",queue[i]);
printf("\n");
}
void main()
{
printf("\t\t\t QUEUE\n");
int ch;
while (1)
{
printf("1.Insert\n2.Delete\n3.Display\n...\t");
scanf("%d",&ch);
switch (ch)
{
case 1: insert();
break;
case 2: delete();
break;
case 3: display();
break;
case 4:exit(0);
default: printf("INVALID INPUT");
break;
}
}
}