Page 517 - Computer science 868 Class 12
P. 517

40             System.out.println("Enter address to insert");
                   41             n=sc.next();

                   42             ob.pushAdd(n);
                   43             break;

                   44             case 2:
                   45             n=ob.popadd();

                   46             if(n.equals("?????"))
                   47               System.out.println("Queue Underflow");

                   48             else
                   49               System.out.println(n+" deleted from queue");

                   50             break;
                   51             case 3:
                   52             ob.show();

                   53             break;

                   54             default: System.out.println("Exit");
                   55          }
                   56              }while(ch>=1&&ch<=3);

                   57          }
                   58      }


                 13.2.2 Applications of Queue
                 The following applications can be performed using a Queue.
                 1.  Queues are widely used in CPU scheduling and Disk scheduling where a resource is shared by multiple devices.
                 2.  Queues are used in Spooling in printers. They manage the printers use especially when the system has more than
                   one printer connected.
                 3.  When we send whatsapp messages to the friends who are offline, the messages are queued in the whatsapp server.
                 4.  Queues are applied as buffers on MP3 players and portable CD players.
                 5.  Queues are applied on operating system to handle the interruption.

                 13.2.3 Drawbacks of Linear Queue
                 We know that the data in linear queue is inserted from the rear end. Suppose after reaching a queue overflow condition,
                 we remove items from the front end. But even though the front end is empty, we cannot insert items as the rear end
                 index has reached the maximum size.

                 13.2.4 Double-Ended Queue
                 A double ended queue or a dequeue is a modified queue in which insertion and deletion are performed from both rear
                 and front the ends. The following operations can thus be performed on a Dequeue.
                 1.  Inserting an element from the front end
                 2.  Inserting an element from the rear end




                                                                                                                       515
                                                                                                       Data Structures  515
   512   513   514   515   516   517   518   519   520   521   522