Repository navigation
Expand file tree
/
Copy pathQueue(Array)
More file actions
93 lines (88 loc) · 1.84 KB
/
Copy pathQueue(Array)
File metadata and controls
93 lines (88 loc) · 1.84 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
85
86
87
88
89
90
91
92
93
#include<stdio.h>
#include<memory.h>
#include<stdlib.h>
#define SIZE 7
int front = -1, rear = -1, queue[SIZE];
void menu();
void enqueue();
void dequqeue();
void peek();
void display();
int main(){
int choice=0;
do{
system("cls");
menu();
printf("Enter your choice:");
scanf("%d",&choice)
switch(choice){
case 1: enquqeue();
break;
case 2: dequeue();
break;
case 3: peek();
break;
case 4: display();
break;
default: printf("Thank you for sharing this program");
break;
}
getch();
}while(choice>0 && choice<5);
return 0;
}
void menu(){
printf("=========================================================\n");
printf(" Menu \n");
printf("=========================================================\n");
printf("->Enter 1 for enqueue operation\n");
printf("->Enter 2 for dequeue operation\n");
printf("->Enter 3 for peek operation\n");
printf("->Enter 4 for display operation\n");
printf("=========================================================");
}
void enqueue(){
int value=0;
printf("Enter your data:");
scanf("%d",&value);
if(rear == SIZE-1){
printf("Queue overflowed");
menu();
}
else if(front == -1 || rear == -1){
front = rear = 0;
queue[front] = value;
}else{
rear++;
queue[rear] = value;
}
}
void dequeue(){
int value=0;
if(front== -1 || front>rear){
printf("Underflow");
}
else{
value = queue[front];
printf("Deleted value is %d",value);
front++;
}
void peek(){
if(front == -1 || front>rear){
printf("Underflow");
}
else{
printf("%d",queue[front]);
}
}
void display(){
if(front==-1 || front>rear){
printf("Queue is empty");
}
else{
int i=0;
for(i=front;i<=rear;i++){
printf("%d->",queue[i]);
}
}
}