Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this pleaaase. Comments explaining what was done would be great

ID: 3567093 • Letter: I

Question

I need help with this pleaaase. Comments explaining what was done would be great as well :-) Thank you! (The .java files that were provided to us have been posted below).

Activity 1: Out-of-Place Sorting can be found here: http://www.chegg.com/homework-help/questions-and-answers/could-someone-please-help-comments-explaining-done-would-great-well-thank-java-files-provi-q6131929

Activity 2: In-Place Sorting

The second activity involves implementing the empty sort_InPlace() method inthe LinkedList class:

This method should be modified to sort the current linked list of cities from smallest to largest (by name or population is fine).

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Demo.java

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

LinkedList.java

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

City.java

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

LinkedListElement.java

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Explanation / Answer

heres the code :


public void sort_InPlace() {
  
   if (isEmpty()) {
return;
}

   LinkedListElement currHead = first;
   LinkedListElement scout = null;
   LinkedListElement agent = null;

   int maxPopulation = INTEGER.MAX;
   String name;
String province;
      
   while(currHead != null) { //selecting one node each
       maxPopulation = currHead.getPopulation();
       agent = currHead;
       scout = currHead.next;
       while (scout != null) { //finding next biggest nodes here and sorting in place
           if (scout.getPopulation() > maxPopulation ){
               maxPopulation = scout.getPopulation();
               name = scout.getName();
               province = scout.getPopulation();

               agent = scout;
           }
           scout = scout.next;
       }
       if(scout != currHead) { // here swapping of data takes place
           scout.setPopulation(currHead.getPopulation());
           scout.setName(currHead.getName());
           scout.setProvince(currHead.getProvince());

           currHead.setPopulation(maxPopulation);
           currHead.setName(name);
           currHead.setProvince(province);
       }
       currHead = currHead.next;
   }
  

}