unit 6,quicksort, dqueue, priority queue added

This commit is contained in:
Tanmay 2023-12-04 10:25:03 +05:30
parent cf9c477b1d
commit 2f37503f03
4 changed files with 291 additions and 0 deletions

BIN
notes/Unit 3/quicksort.ppt Normal file

Binary file not shown.

133
notes/Unit 6/Dqueue.cpp Normal file
View File

@ -0,0 +1,133 @@
#include<iostream>
using namespace std;
#define SIZE 20
class dequeue
{
int a[20],f,r;
public:
dequeue();
void insert_at_beg(int);
void insert_at_end(int);
void delete_fr_front();
void delete_fr_rear();
void show();
};
dequeue::dequeue()
{
f=-1;
r=-1;
}
void dequeue::insert_at_end(int i)
{
if(r>=SIZE-1)
cout<<"insertion is not possible, overflow!!!!";
else
{
if(f==-1)
{
f++;
r++;
}
else
r=r+1;
a[r]=i;
cout<<"Inserted item is"<<a[r];
}
}
void dequeue::insert_at_beg(int i) {
if(f==-1) {
f=0;
a[++r]=i;
cout<<" inserted element is:"<<i;
}
else if(f!=0)
{
a[--f]=i;
cout<<" inserted element is:"<<i;
}
else {
cout<<" insertion is not possible, overflow!!!";
}
}
void dequeue::delete_fr_front() {
if(f==-1) {
cout<<"deletion is not possible::dequeue is empty";
return;
}
else {
cout<<"the deleted element is:"<<a[f];
if(f==r) {
f=r=-1;
return;
} else
f=f+1;
}
}
void dequeue::delete_fr_rear() {
if(f==-1) {
cout<<"deletion is not possible::dequeue is empty";
return;
}
else {
cout<<"the deleted element is:"<<a[r];
if(f==r) {
f=r=-1;
} else
r=r-1;
}
}
void dequeue::show() {
if(f==-1) {
cout<<"Dequeue is empty";
} else {
for(int i=f;i<=r;i++) {
cout<<a[i]<<" ";
}
}
}
int main()
{
int c,i;
dequeue d;
do//perform switch opeartion
{
cout<<" 1.insert at beginning";
cout<<" 2.insert at end";
cout<<" 3.show";
cout<<" 4.deletion from front";
cout<<" 5.deletion from rear";
cout<<" 6.exit";
cout<<" enter your choice:";
cin>>c;
switch(c)
{
case 1:
cout<<"enter the element to be inserted";
cin>>i;
d.insert_at_beg(i);
break;
case 2:
cout<<"enter the element to be inserted";
cin>>i;
d.insert_at_end(i);
break;
case 3:
d.show();
break;
case 4:
d.delete_fr_front();
break;
case 5:
d.delete_fr_rear();
break;
default:
cout<<"invalid choice";
break;
}
}while(c!=7);
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,158 @@
#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 print() { //print the data of Queue
int i;
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;
}
}
}
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++;
}
}
int main()
{
string data;
int opt,n,i,p;
cout<<"Enter Your Choice:-"<<endl;
do {
cout << "\n 1 : Insert the Data in Queue" << endl << "2: Display the Queue " << endl << "3: Delete the data from the Queue"
<< endl << "0 for Exit"<< endl;
cin >> opt;
switch(opt) {
case 1:
cout << "Enter the number of Patient" << endl;
cin >> n;
i = 0;
while(i < n) {
cout << "Enter your name of the patient : ";
cin >> data;
ifnotdoagain:
cout << "Enter your Priority (0: serious, 1: non-serious, 2: general checkup) : ";
cin >> p;
switch(p) {
case 0:
enqueue(data,SERIOUS);
break;
case 1:
enqueue(data,NONSERIOUS);
break;
case 2:
enqueue(data,CHECKUP);
break;
default:
goto ifnotdoagain;
}
i++;
}
break;
case 2:
print();
break;
case 3:
dequeue();
break;
case 0:
cout << "Bye Bye !" << endl;
break;
default:
cout<<"Incorrect Choice"<<endl;
}
}while(opt!=0);
return 0;
}