Homework: Queue III; Selection Sort


This homework is necessary preparation for the lab. Make sure you type your answers in a file you bring to the lab so that you will be able to quickly copy and paste them into the file provided in the lab.

  1. Implement the static method removeMin declared as follows:

    To compare two Strings, use the Comparator<String> method compare (see Queue slides 45-50). Do not call sort in your code for removeMin, as this would miss the point of the problem; see below.

  2. Implement the static method sort declared below that sorts a Queue<String> q using the "selection sort" algorithm according to the given order. This algorithm repeatedly calls removeMin until q is empty, placing the items it returns one-by-one into a temporary queue, and then finally transferring this temporary object into q.