Friday, 30 September 2011

deletion of the queue




//DELETION (dequeue) ALGORITHM FOR QUEUES
 
algorithm del()
{
  declare x;
  if rear==-1, return (-1) 
 else
 begin

     x=a[f];
     f=f+1;
    if(f>r) then reinitialize f=0, r=-1
   return deleted value;
end
//function for deletion (dequeue) from the queue:

template<class T>
T del()
{
  T x;
  if(r==-1)
    return(-1);
  else
  {
    x=a[f];
    f++;
  }
  if(f>r)
 {
   f=0;
   r=-1;
 }
 return(x);
}

//Note: x=q.del();

Note 2:
dequeue means to remove data from the queue, generally from the "front" of the queue. This can sometimes be called "pop".

Note that "push" and "pop" can be confused with the stack operations "push" and "pop", so "enqueue" and "dequeue" are explicit and less ambiguous.


 Queues

No comments:

Post a Comment