Page 176 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 176

Unit 10: Queues




           if (front->next==NULL)                                                               Notes
           {
           free(front);
           queueptr = front = rear = NULL;
          }
          else
          {
          front=front->next;
          free(queueptr);
          queueptr = front;
          }
          }
          }

          Self Assessment

          Fill in the blanks:
          6.   In a ..................... queue, front will point to one position less to the first element anti-clock
               wise.
          7.   ..................... representation of a circular queue is more efficient as it uses space more
               efficiently, of course with the extra cost of storing the pointers.
          10.4 Priority Queue


          A priority queue is a collection of elements where each element is assigned a priority and the
          order in which elements are deleted and processed is determined from the following rules:
          An element of higher priority is processed before any element of lower priority.
          Two elements with the same priority are processed according to the order in which they are
          added to the queue.

                 Example: An example of a priority queue can be time sharing system: programs of high
          priority are processed first, and programs with the same priority form a standard queue.

          10.4.1 Array Implementation of Priority Queue

          One way to represent priority queue is through arrays.
          If an array is used to store the elements of priority queue then insertion is easy but deletion of
          elements would be difficult. This is because while inserting elements in the priority queue they
          are not inserted in an order. As a result, deleting an element with the highest priority would
          require examining the entire array to search for such an element.



             Did u know? An element in a queue can be deleted from the front end only.








                                           LOVELY PROFESSIONAL UNIVERSITY                                   169
   171   172   173   174   175   176   177   178   179   180   181