KUMAR SHIVAM

Explain Algorithm for Enqueue operation  and Algorithm for Dequeue operation using array ? 

Data Structures and Algorithms

Answer in Short

Enqueue: Add an element to the end of the queue. Dequeue: Remove an element from the front of the queue.

Explanation

1318    0

==> Algorithm for Enqueue operation using array--

        Step 1. start

        Step 2. if (front == (rear+1)%max)

                   Print error “circular queue overflow “

       Step 3. else { rear = (rear+1)%max

                   Q[rear] = element;

                  If (front == -1 ) f = 0;

                 }

       Step 4. stop

 

 

==> Algorithm for Dequeue operation using array--

        Step 1. start

        Step 2. if ((front == rear) && (rear == -1))

                   Print error “circular queue underflow “

       Step 3. else { element = Q[front]

                If (front == rear) front=rear = -1

              Else

             Front = (front + 1) % max

                   }

     Step 4. stop



Share:   

More Questions from Data Structures and Algorithms Module 2