-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue.c
More file actions
84 lines (83 loc) · 1.32 KB
/
queue.c
File metadata and controls
84 lines (83 loc) · 1.32 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
82
83
84
#include<stdio.h>
#include<conio.h>
int f=-1,r=-1,a[5];
void insertion(int);
void deletion();
void search(int);
void change(int,int);
void display();
int main()
{
int z,p;
char c;
printf("1.insertion\n2.deletion\n3.search\n4.change\n5.display\n6.quit\n");
for(;1;)
{
printf("\nenter your choice ");
c=getche();
switch (c)
{
case '1': printf("\nenter element..");
scanf("%d",&z);
insertion(z);
break;
case '2': deletion();break;
case '3': printf("\nenter place from front..");
scanf("%d",&p);
search(p);
break;
case '4': printf("\nenter place & new value..");
scanf("%d %d",&p,&z);
change(z,p);
break;
case '5': display();break;
case '6': return 0;break;
default: printf("\nwrong choice!!!");
}
}
}
void insertion(int z)
{
if(r<4)
{
r++;
a[r]=z;
if(f==-1)f++;
}
else
printf("queue is full.\n");
}
void deletion()
{
if(f>=0&&f<=r)
{
f++;
printf("\n%d is deleted..",a[f-1]);
}
else
printf("\nno value in queue\n");
}
void search(int p)
{
if((p-1)<=r-f&&p>0)
printf("\n%d element from front is %d\n",p,a[f+p-1]);
else
printf("\nerror!!!!!\n");
}
void change(int z,int p)
{
if((p-1)<=(r-f)&&p>0)
{
a[f+p-1]=z;
printf("\n%d element from front is %d\n",p,a[f+p-1]);
}
else
printf("\nnot possible\n");
}
void display()
{
int x;
printf("\n");
for(x=f;x<=r;x++)
printf("%d\n",a[x]);
}