items are kept in sorted order it' an ascending-priority queuein which the item with the smallest key has the highest priority and is accessed with remove((if the highest-key item were accessedit would be descending-priority queue the minimum-key item is always at the top (highest indexin the arrayand the largest item is always at index figure shows the arrangement when the applet is started initially there are five items in the queue figure the priorityq workshop applet insert try inserting an item you'll be prompted to type the new item' key value into the number field choose number that will be inserted somewhere in the middle of the values already in the queue for examplein figure you might choose thenas you repeatedly press insyou'll see that the items with smaller keys are shifted up to make room black arrow shows which item is being shifted once the appropriate position is foundthe new item is inserted into the newly created space notice that there' no wraparound in this implementation of the priority queue insertion is slow of necessity because the proper in-order position must be foundbut deletion is fast wraparound implementation wouldn' improve the situation note too that the rear arrow never movesit always points to index at the bottom of the array delete the item to be removed is always at the top of the arrayso removal is quick and easythe item is removed and the front arrow moves down to point to the new top of the array no comparisons or shifting are necessary in the priorityq workshop appletwe show front and rear arrows to provide comparison with an ordinary queuebut they're not really necessary the algorithms know that the front of the queue is always at the top of the array at nitems- and they insert items in ordernot at the rear figure shows the operation of the priorityq class methods peek and new you can peek at the minimum item (find its value without removing itwith the peek buttonand you can create newemptypriority queue with the new button other implementation possibilities