Friday, 30 September 2011

INSERTION FOR QUEUE

WRITE A ALGORITHM FOR INSERTION (enqueue ) IN THE QUEUE
algorithm insert(data x)
{
 begin
   if queue is full, deletion is not possible,
  else
  begin
    r=r+1 ;(move rear(r) to next location)
   a[r]=x;
 end
}
//Note: insertion (enqueue) in the queue is only from rear end i .e r

//implement (write a program) insertion (enqueue) function for queue
void insert(int x)
{
  if(r= =size-1)
   cout<<"insertion is not possible, queue is full\n";
 else
   {
      r++;
      a[r]=x;
  }
}

Note:
 enqueue means to add data to the queue, generally at the "back" of the queue. In Stack point of view we use push operation, where as in Queue point of view we use term enqueue. This can sometimes be called "push".
 Queues operations (or) implementing the Queues

No comments:

Post a Comment