forked from happy522/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue using array
More file actions
74 lines (70 loc) · 1.49 KB
/
Queue using array
File metadata and controls
74 lines (70 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
#include<stdio.h>
#include<conio.h>
#include<stdbool.h>
#define MAX 10
int array[MAX], front=1, rear=0;
bool isFull(){
bool isfull;
if(rear==MAX){
isfull=true;
}
else{
isfull=false;
}
return isfull;
}
bool isEmpty(){
bool isempty;
if(front>rear){
isempty = true;
}
else{
isempty = false;
}
return isempty;
}
void insert(int ele){
if(!isFull()){
rear++;
array[rear]=ele;
}
else{
printf("\nCan't insert %d element.\n Queue is full.",ele);
}
}
void delete(){
if(!isEmpty()){
int popped = array[front];
front++;
printf("\nElement popped is %d",popped);
}
else{
printf("\nCan't delete element.\n Queue is empty.");
}
}
void display(){
for(int i=front;i<=rear;i++){
printf("\nElement[%d] is %d",i,array[i]);
}
}
void main(){
char yn;
int ch,ele;
do{
printf("\n 1: For Push\n 2: For Pop\n 3: For Display\n Your choice:");
scanf("%d",&ch);
switch(ch){
case 1: printf("\nEnter Element you want to push: ");
scanf("%d",&ele);
insert(ele);
break;
case 2: delete();
break;
case 3: display();
break;
default:printf("\nWrong choice.");
}
printf("\n\nDo you want to continue? Enter Y for yes: ");
scanf(" %c",&yn);
}while(yn=='Y'||yn=='y');
}