-
Notifications
You must be signed in to change notification settings - Fork 0
/
e20.cpp
157 lines (138 loc) · 3.35 KB
/
e20.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include<iostream>
#include<string>
#define n 20
#define serious 10
#define nonserious 5
#define checkup 1
using namespace std;
string q[n];
int pr[n];
int r = -1,f = -1;
//-------------------------------------------------------------------------------------------
void enqueue(string data,int p)//Enqueue function to insert data and its priority in queue
{
int i;
if((f==0)&&(r==n-1)) //Check if Queue is full
cout<<"Queue is full";
else {
if(f==-1) { //if Queue is empty
f = r = 0;
q[r] = data;
pr[r] = p;
}
//-----------------------------------------
else if(r == n-1){ //if there there is some elemets in Queue
for(i=f;i<=r;i++) {
q[i-f] = q[i];
pr[i-f] = pr[i];
r = r-f;
f = 0;
for(i = r;i>f;i--) {
if(p>pr[i]) {
q[i+1] = q[i];
pr[i+1] = pr[i];
}
else break;
q[i+1] = data;
pr[i+1] = p;
r++;
}
}
}
//------------------------------------------
else {
for(i = r;i>=f;i--) {
if(p>pr[i]) {
q[i+1] = q[i];
pr[i+1] = pr[i];
}
else break;
}
q[i+1] = data;
pr[i+1] = p;
r++;
}
}
}
//-----------------------------------------------------------------------------------------------------
void dequeue() { //remove the data from front
if(f == -1) {
cout<<"Queue is Empty";
}
else {
cout<<"deleted Element ="<<q[f]<<endl;
cout<<"Its Priority = "<<pr[f]<<endl;
// if(f==r) f = r = -1;
// else f++;
}
}
//---------------------------------------------------------------------------------------------------------
void display() { //print the data of Queue
int i;
if(f==-1){
cout<<"No records found";
return;
}
for(i=f;i<=r;i++) {
cout << "Patient's Name - "<<q[i];
switch(pr[i]) {
case 1:
cout << " Priority - 'Checkup' " << endl;
break;
case 5:
cout << " Priority - 'Non-serious' " << endl;
break;
case 10:
cout << " Priority - 'Serious' " << endl;
break;
default:
cout << "Priority not found" << endl;
}
}
}
//---------------------------------------------------------------------------------------------------------
int main() {
string data;
int p,opt;
cout<<"\n---------------------------\n";
cout<<"1)insert data\n2)display data\n3)delete data\n4)exit\n";
cout<<"\n---------------------------\n";
cout<<"Enter your choice:-";
cin>>opt;
switch(opt){
case 1:
cout<<"Enter patient name:-";
cin>>data;
cout<<"Enter priority of the patient(1-serious,2-non-serious,3-general checkup)";
cin>>p;
switch(p){
case 1:
enqueue(data,serious);
break;
case 2:
enqueue(data,nonserious);
break;
case 3:
enqueue(data,checkup);
break;
default:
cout<<"Enter valid priority value:-";
break;
}
break;
case 2:
display();
break;
case 3:
dequeue();
break;
case 4:
cout<<"------------exited-----------";
break;
default:
cout<<"Enter valid choice";
break;
}
return 0;
}
//-----------------------------------------------------------------------------------------------------------