If Any Required Program Please Ask In Comment I Will Help You(any Program in JAVA or C++) . . THANKS FOR VISITING MY BLOG!

If U LIKE MY PROFILE RAISE YOUR HAND IF U NOT RAISE UR STANDARD. Powered by Blogger.

Sunday, October 21, 2018

PROGRAM FOR PRIORITY QUEUE FOR DESCENDING ORDER.



#include <iostream>
#include <stdlib.h>
#include <conio.h>

using namespace std;

template <class Type>

class PQueue
{
private:
Type *Queue;
int Size, Rear;

public:
PQueue(int Siz)
{
Size = Siz;

Queue = new Type[Siz];

Rear = -1;
}

void EnQueue(Type Ch)
{
if (Rear == Size - 1)
{
cout << "\nQueue OverFlowed!!!\n" << endl;
exit(1);
}

Queue[++Rear] = Ch;
}

Type dQueue()
{
int Index = Maxi();
Type Value = Queue[Index];

if (IsEmpty())
{
cout << "\nQueue UnderFlowed!!!\n" << endl;
exit(1);
}

for (int I = Index; I <= Rear; I++)
Queue[I] = Queue[I + 1];

Rear--;
return Value;
}

inline bool IsEmpty()
{
return (Rear == -1);
}

int Maxi()
{
int Index;
Type Big = Queue[0];

for (int I = 1; I <= Rear; I++)
{
if (Big < Queue[I])
{
Index = I;
Big = Queue[I];
}
}

return Index;
}
};

int main()
{
PQueue<int> Obj(10);

Obj.EnQueue(3);
Obj.EnQueue(5);
Obj.EnQueue(7);
Obj.EnQueue(8);
Obj.EnQueue(1);

for (int I = 0; I < 5; I++)
cout << Obj.dQueue() << endl;

getch();
return 0;
}

0 comments:

Post a Comment