Page 518 - Computer science 868 Class 12
P. 518

3.  Deleting an element from the front end
              4.  Deleting an element from the rear end
              A Dequeue can have two variations which are as follows:

              •  Input Restricted Dequeue: In this form, insertion can only be done from one end and deletion can be done from
                 both ends.

              •  Output Restricted Dequeue: Here, deletion can only be done from one end and insertion can be done from both
                 the ends.

              The algorithms for insert and delete operations of a Dequeue from both front and rear ends are given below.

              Let us consider an integer array dqu[] whose front and rear indices are represented by variables front and rear respectively.
              1.  Following is the algorithm to insert an item from rear end of Dequeue. This operation is similar to Queue.
                void insertRear(int dqu[] , int max , int val)
                 Step 1:  Start.

                 Step 2:  Initialise front and rear to 0
                 Step 3:  If rear = max then display “Full from rear ….Dequeue Overflow”, go to Step 8
                 Step 4:  Increment rear by 1
                 Step 5:  Assign dqu[rear]=val

                 Step 6:  Accept cont
                 Step 7:  If cont=“Yes” or cont=“yes” then go to Step 3
                 Step 8:  Stop.
              2.  Following is the algorithm to insert an item from front end of the Dequeue.
                 void insertFront(int dqu[] , int max , int val)

                 Step 1:  Start.
                 Step 2:  Initialise front and rear to 0
                 Step 3:  If front = 0 then display “Full from front….Dequeue Overflow”, go to Step 8

                 Step 4:  Assign dqu[front]= val
                 Step 5:  Decrement front by 1
                 Step 6:  Accept cont
                 Step 7:  If cont=“Yes” or cont=“yes” then go to Step 3
                 Step 8:  Stop.

              3.  Following is the algorithm to delete an element from the front end of the Dequeue. This operation is similar to
                 normal Queue.
                 int deleteFront(int qu[] , int max , int front , int rear)
                 Step 1:  Start.

                 Step 2:  If rear = front then display “Empty from front end..Dequeue Underflow”, return value
                 Step 3:  Increment front by 1
                 Step 4:  Return dqu[front]
                 Step 5:  Accept cont
                 Step 6:  If cont=“Yes” or cont=“yes” then go to Step 2

                 Step 7:  Stop.


                516516  Touchpad Computer Science-XII
   513   514   515   516   517   518   519   520   521   522   523