code: private void mergeJobs (LinkedList<JobInProgress> jobsToReinsert, TaskType taskType) {
      LinkedList<JobInProgress> sortedJobs = (taskType == TaskType.MAP) ?
        sortedJobsByMapNeed : sortedJobsByReduceNeed;
      Comparator<JobInProgress> comparator = (taskType == TaskType.MAP) ?
        mapComparator :  reduceComparator;
  
      // for each job to be reinserted
      for(JobInProgress jobToReinsert: jobsToReinsert) {
  
        // look at existing jobs in the sorted list starting with the head
        boolean reinserted = false;
        ListIterator<JobInProgress> iter = sortedJobs.listIterator(0);
        while (iter.hasNext()) {
          JobInProgress job = iter.next();
          if (comparator.compare(jobToReinsert, job) < 0) {
            // found the point of insertion, move the iterator back one step
            iter.previous();
            // now we are positioned before the job we compared against
            // insert it before this job
            iter.add(jobToReinsert);
            reinserted = true;
            break;
          }
        }
        if (!reinserted) {
          sortedJobs.add(jobToReinsert);
        }
      }
    }
docs: reinsert a set of jobs into the sorted jobs for a given type (MAP/REDUCE)
  the re-insertion happens in place.
  we are exploiting the property that the jobs being inserted will most likely end
  up at the head of the sorted list and not require a lot comparisons