thepq insert( )thepq insert( )thepq insert( )thepq insert( )while!thepq isempty(double item thepq remove()system out print(item ")/end while system out println("")/end main(/ ///end class priorityqapp in main(we insert five items in random order and then remove and display them the smallest item is always removed firstso the output is the insert(method checks if there are any itemsif notit inserts one at index otherwiseit starts at the top of the array and shifts existing items upward until it finds the place where the new item should go then it inserts it and increments nitems note that if there' any chance the priority queue is full you should check for this possibility with isfull(before using insert(the front and rear fields aren' necessary as they were in the queue classbecauseas we notedfront is always at nitems- and rear is always at the remove(method is simplicity itselfit decrements nitems and returns the item from the top of the array the peekmin(method is similarexcept it doesn' decrement nitems the isempty(and isfull(methods check if nitems is or maxsizerespectively efficiency of priority queues in the priority-queue implementation we show hereinsertion runs in (ntimewhile deletion takes ( time we'll see how to improve insertion time with heaps in parsing arithmetic expressions so far in this we've introduced three different data storage structures let' shift gears now and focus on an important application for one of these structures this application is parsing (that isanalyzingarithmetic expressions like + or *( + or (( + )* )+ *( - )and the storage structure it uses is the stack in the brackets java programwe saw how stack could be used to check whether delimiters were formatted correctly stacks are used in similaralthough more complicatedway for parsing arithmetic expressions in some sense this section should be considered optional it' not prerequisite to the rest of the bookand writing code to parse arithmetic expressions is probably not something you need to do every dayunless you are compiler writer or are designing