forked from Vatsalparsaniya/Data-Structure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple_Queue.c
More file actions
75 lines (66 loc) · 1.49 KB
/
Copy pathSimple_Queue.c
File metadata and controls
75 lines (66 loc) · 1.49 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
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 5
int front=-1,rear=-1,q[MAXSIZE];
void insert(int a){
if(rear>=MAXSIZE){
printf("sorry!! \n queue is full \n");
}
else{
if(front==-1) front=0;
rear++;
q[rear]=a;
printf("element %d is successfully added\n",a);
}
}
void delete(){
if(front<0){
printf("Error!! \n Underflow condition\n");
}
else if(front==rear){
q[front]=0;
front=-1;
rear=-1;
printf("element successfully delete\n");
}
else{
q[front]=0;
front++;
printf("element successfully delete\n");
}
}
void display(){
int i=0;
for(i=0;i<=MAXSIZE;i++){
printf(" %d |",q[i]);
}
printf("\n");
}
int main(){
int choise=0,inse;
printf(" 1) insert element \n 2) delete element \n 3) display queue \n 4) exit\n ");
while(choise != 4){
printf("enter your choice : ");
scanf("%d",&choise);
switch(choise)
{
case 1:
printf("enter a number which you want to add in queue:");
scanf("%d",&inse);
insert(inse);
break;
case 2:
printf("you chose delete option\n");
delete();
break;
case 3:
printf("you chose display option\n");
display();
break;
case 4:
printf("\nI hope u enjoy this program \n");
break;
}
}
return 0;
}