Page 512 - Computer science 868 Class 12
P. 512

Step 2: 23 deleted from queue
                                                                                   17      23      28

                                                                                        front = 2  rear = 3

                        Step 3:  28 deleted from queue
                                                                                   17      23      28
                                                                                                front = 3
                                                                                                 rear = 3

                        Step 4:   Front  =  rear  so  no  further  deletion  is
                               possible Queue empty.
                                                                         queue empty            front = 3
                                                                                                 rear = 3

              The algorithm for insertion operation in Queue is given below.
              void insert(int qu[], int max, int val)
              Step 1:  Start.

              Step 2:  Initialise front and rear to 0
              Step 3:  If rear = max then display “Queue Overflow”, go to Step 8

              Step 4:  Increment rear by 1
              Step 5:  Assign qu[rear]=val
              Step 6:  Accept cont

              Step 7:  if cont=“Yes” or cont=“yes” then go to Step 3
              Step 8:  Stop.

              The algorithm for deletion operation in Queue is given below.
              int delete(int qu[], int max, int front, int rear)
              Step 1:  Start.

              Step 2:  If rear = front then display “Queue Underflow”, exit
              Step 3:  Increment front by 1

              Step 4:  Return qu[front]
              Step 5:  Accept cont

              Step 6:   if cont=“Yes” or cont=“yes” then go to Step 2
              Step 7:  Stop.

              The algorithm to display the contents of Queue is given below.
              void display(int qu[] , int front, int rear)

              Step 1:  Start.
              Step 2:  Initialise counter i to front
              Step 3:  Repeat Steps 4 to 5 while i < rear

              Step 4:  Display qu[i]
              Step 5:  Increase i by 1

              Step 6:  Stop.


                510510  Touchpad Computer Science-XII
   507   508   509   510   511   512   513   514   515   516   517