size(isempty(isempty(insert( ,voffer(new pqentry( , )or add(new pqentry( , )min(peek()or element(removemin(poll()or remove(sorting with priority queue another important application of priority queue is sortingwhere we are given collection of elements that can be compared according to total order relationand we want to rearrange them in increasing order (or at least in nondecreasing order if there are tiesthe algorithm for sorting with priority queue qcalled priorityqueuesortis quite simple and consists of the following two phases in the first phasewe put the elements of into an initially empty priority queue by means of series of insert operationsone for each element in the second phasewe extract the elements from in nondecreasing order by means of series of nremovemin operationsputting them back into in order we give pseudo-code for this algorithm in code fragment assuming that is sequence (pseudo-code for different type of collectionsuch as an array list or node listwould be similarthe algorithm works correctly for any priority queue pno matter how is implemented howeverthe running time of the algorithm is determined by the running times of operations insert and removeminwhich do depend on how is implemented indeedpriorityqueuesort should be considered more sorting "schemethan sorting "algorithm,because it does not specify how the priority queue is implemented the priorityqueuesort scheme is the paradigm of several popular sorting algorithmsincluding selectionsortinsertion-sortand heap-sortwhich we discuss in this