Priority Queue in C++

Implementation of  Priority Queue on the bases of Acceding Order in C++ Using Arrays and Classes 
Assignment Question: ☺☺☺

// copyright@2014 ☻ usman siddique 
//pcphunt.blogsopt.com

#include<iostream.h>
#include<conio.h>
class queue{
private:
int front,rear,max,i,temp;
int *queuearr;
public:
queue()
{
cout<<"\nEnter the size of Queue: ";
cin>>max;
i=temp=0;
front=0,rear=-1;
int *Queue=new int[max];
}
void insert(int n)
{
if(rear==max)
cout<<"\nQueue is full\n";
else
  {
   rear=rear+1;
   queuearr[rear]=n;
if(queuearr[rear]<queuearr[rear-1])       //This part of code check it
      {                                            //and arreange in accending order
for(i=rear;i!=0;i--)
{
if(queuearr[i]<queuearr[i-1])  {
temp=queuearr[i-1];
queuearr[i-1]=queuearr[i];
queuearr[i]=temp;              }  //2nd if
} //for
      }   //if
  }        //else
}
void Delete()
{
if(front==-1 && rear==-1)
cout<<"\nQueue is empty\n";
else
cout<<"\nThe Queue element "<<queuearr[front]<<" is Deleted\n";
for(front=0;front<rear;front++)    {
queuearr[front]=queuearr[front+1]; }rear=rear-1;
}
void display()
{
cout<<"\n\npcphunt.blogsopt.com\n\n";

for(int i=0;i<=rear;i++)
cout<<"\nvalue is :"<<queuearr[i];
}
};
void main()
{
clrscr();
int a=0,value=0;
queue obj;
while(getch()!=27)     //check while escap key press :)
{
cout<<"\n \n\n\t\tSelect an option :\n 1   for Insert\n 2   for Delete\n 3   for Display ";
cin>>a;
clrscr();
switch(a)
{
case 1:
{
cout<<"\nEnter value for index: ";
cin>>value;
obj.insert(value);
break;
}
case 2:
obj.Delete();
break;
case 3:
obj.display();
break;
}
cout<<"\n\n\t   || Press Esc Key to exit || Any Key For next Operation  ||";
}
}


4 comments

Anonymous said...

Thankx Usman its my assignment i also need D-Queue Program upload it plz :)

Anonymous said...

thats fine (Y)

Programming Seeker said...

wellcome

Programming Seeker said...

thankx

Powered by Blogger.