C++ Tryit Editor v1.0
Wed Jan 26 2022 21:01:04 GMT+0000 (Coordinated Universal Time)
Saved by
@zkilo404
#include<iostream>
#include<conio.h>
using namespace std;
class PQue
{
private:
int PQ[5][5];
int front[5];
int rear[5];
public:
PQue()
{
for (int i = 0; i < 5; i++)
{
front[i] = rear[i] = -1;
for (int j = 0; j < 5; j++)
{
PQ[i][j] = 0;
}
}
}
void insert(int priority, int value)
{
if (front[priority] == -1 && rear[priority] == 5 - 1)
{
cout << "Overflow !!! " << endl;
}
else
{
PQ[priority][++rear[priority]] = value;
}
}
int remove(int priority)
{
if (front[priority] == rear[priority])
{
cout << "Underflow !!! " << endl;
return -1;
}
else
{
return PQ[priority][++front[priority]];
}
}
void removeAll()
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
cout << remove(i) << endl;
}
}
}
};
int main()
{
PQue A;
A.insert(1, 7);
A.insert(1, 8);
A.insert(1, 2);
A.insert(1, 6);
A.insert(1, 4);
for (int i = 0; i < 5; i++)
{
cout << A.remove(1) << endl;
}
_getch();
return 0;
}
content_copyCOPY
https://www.w3schools.com/cpp/trycpp.asp?filename
Comments