Friday, 18 January 2013

Priority Queue


By on 09:08

Priority Queue is same as normal queue like it has a front and rear end,item inserted from rear and deleted from front end but it is more specialised structure as compare to queue.In Priority Queue each items has priority value.It is used in c,c++,java,c# etc.

Type of Priority Queue:-

1)Ascending Priority Queue(Deletion from smallest value).

2)Descending Priority Queue(Deletion from largest value).


Example(Program/implementation/algorithm  for Priority Queue):-




void add(int x){


if(rear==50)
cout<<"queue is full";
else
{
q[r]=x;
}
}
void delete()
{
max=q[f];
for(i=f;i<r;i++)
{
if(q[i]>max)
{
max=q[i];
position=i;
}
}
for(j=position;j>f;j--)
q[j]=q[j-1];
f++;
cout<<"deleted element="<<max;
}
void display()
{

for(int i=f;i<f;i++)
cout<<"\n"<<q[i];
}
};



That's all about Priority Queue in data structure


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...