Repository navigation
Expand file tree
/
Copy pathP4.c
More file actions
70 lines (67 loc) · 1.35 KB
/
Copy pathP4.c
File metadata and controls
70 lines (67 loc) · 1.35 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
#include<stdio.h>
#define SIZE 10
int q[SIZE];
int front = 0, rear = 0;
void insertq(int item)
{
if((rear+1) % SIZE == front)
printf("Queue is full");
else
{
rear = (rear+1) % SIZE;
q[rear] = item;
printf("Inserted %d \n",item);
}
}
void deleteq()
{
if(front == rear)
printf("Queue is empty\n");
else
{
front = (front + 1) % SIZE;
printf("Deleted %d\n",q[front]);
}
}
void searchq(int item)
{
int i = (front + 1) % SIZE;
int pos = 1;
while(i != (rear + 1) % SIZE)
{
if(q[i] == item)
{
printf("Found at position %d\n",pos);
return;
}
i = (i + 1)% SIZE;
pos++;
}
printf("Not found\n");
}
int main()
{
int item, opt = 0;
while(opt != 4)
{
printf("\n1.Insert\n2.Delete\n3.Search\n4.Exit\nOption : ");
scanf("%d", &opt);
switch(opt)
{
case 1 : printf("Data : ");
scanf("%d",&item);
insertq(item);
break;
case 2 : deleteq();
break;
case 3 : printf("Number to search : ");
scanf("%d",&item);
searchq(item);
break;
case 4 : printf("Program ended\n");
break;
default : printf("Invalid options\n");
}
}
return 0;
}