Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

FinalExam Review Spring2006: Reverse the Sort

Questions? Answers? Comments? Comments on Questions or Answers?
(Back to Final Exam Review Spring2006)



Um......I'm lost.

So, after the while loop, I guess we could put in some kind of if loop, maybe something like

if (compareEvent.getTime() > considered.getTime()) {
elements.set(compare,0);}

but I don't know how to check to see if the event is larger than all the events. The time thing confuses me. Maybe we could put in a for loop of some sort that checks the if statement against all of the events? Help.


Yeah... well it seems like you'd just have to change it from being greater than to less than... You know?
// While the considered event is greater than the compared event, <-- So while the ConE is LESS than the ComE....
      // it's in the wrong place, so move the elements up one.
      compareEvent = (SimEvent) elements.get(compare-1);
      while (compareEvent.getTime() <
             considered.getTime())  {
        elements.set(compare,elements.get(compare-1));
        compare = compare-1;
        // If we get to the end of the array, stop
        if (compare <= 0) {break;}


I think that would work, because all the ones that are less than that even will move down and you'll put it in when you find one that is greater than it. Or something... Does that sound right? It seems really simple to just change a greaterthan/lessthan sign... but then again, you're just reversing the order....

^I believe that is correct. Mark did say that you probably only have to change one line to reverse the sorter.



Link to this Page