in main(we insert five items in random orderand then remove and display them the smallest item is always removed firstso the output is the insert(method checks whether 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 the item and increments nitems note that if there' any chance the priority queue is fullyou should check for this possibility with isfull(before using insert(the front and rear fields aren' necessary as they were in the queue class becauseas 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 such as + or *( + or (( + )* )+ *( - the storage structure it uses is the stack in the brackets java program (listing )we 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 pocket calculators alsothe coding details are more complex than any we've seen so far howeverseeing this important use of stacks is educationaland the issues raised are interesting in their own right as it turns outit' fairly difficultat least for computer algorithmto evaluate an arithmetic expression directly it' easier for the algorithm to use two-step process