Page 154 - DCAP407_DATA_STRUCTURE
P. 154

Unit 8:  Queues



                               6.  When the user enters 2, the del()  function is called.  In this function, the if
                                   loop checks if the value of F is equal to NULL. If the condition is true, then
                                   program prints the message “QUEUE UNDERFLOW”. Else, F is assigned to
                                   new, and the element in F is deleted. The pointer F is set free.
                               7.  When the user enters 3, the function disp() is called. In this function, the if
                                   loop checks if the value of F is equal to NULL. If the condition is true, then
                                   the  program prints the message  “QUEUE is EMPTY”. Else, it displays the
                                   elements present in the queue along with their priority.
                               8.  When the user enters 4, the program terminates.


                                 1.  Create a circular queue having an element storage capacity of 5. Insert 4
                                     elements into the queue. Delete first two elements and insert an element at
                                     the position F=1 and R=3.
                                 2.  Create a priority queue having an element capacity of 3. Insert the elements
                                     100 having priority 2, 200 having priority 1, and 300 having priority 3. Try
                                     deleting element with priority 2. Analyze the result.

               8.5   Summary

               •    A queue is an ordered collection of items in which deletion takes place at the front and insertion at
                    the rear of the queue.
               •    The basic operations performed on a queue include inserting an element at the rear end and
                    deleting an element at the front end.

               •    In a memory, a queue can be represented in two ways; by representing the way in which the
                    elements are  stored in the memory, and by naming the  address to which the front and rear
                    pointers point to.
               •    The different types of queues are double ended queue, circular queue, and priority queue.
               8.6    Keywords
               Dequeue: Process of deleting elements from the queue.
               Enqueue: Process of inserting elements into queue.

               Front End: Refers to the first node in the queue.
               Rear End: Refers to the last node in the queue.
               8.7   Self Assessment

               1.   State whether the following are true or false.
                    (a)  Insertions and deletions can happen at the front or the rear end of the priority queue.
                    (b)  A double ended queue is also known as deque.
                    (c)   If the queue is not empty, the items are deleted at the rear end of the queue.
               2.   Fill in the blanks.
                    (a)  The end of the queue from which the element is deleted is termed as
                       …………………………….  and the end at which the new element is added is termed as
                       …………………………….
                    (b)  While inserting an element in a basic queue, the rear pointer is always………………………
                    (c)   In a ……………………………. queue, insertion and deletion operations are independent of
                       one another.




                                        LOVELY PROFESSIONAL UNIVERSITY                          147
   149   150   151   152   153   154   155   156   157   158   159