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

Could someone please help me with this? Comments explaining what was done would

ID: 3567092 • Letter: C

Question

Could someone please help me with this? 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

The first activity involves modifying the sort_OutOfPlace() method in the LinkedList class:

Activity 2: In-Place Sorting can be found here: http://www.chegg.com/homework-help/questions-and-answers/need-help-pleaaase-comments-explaining-done-would-great-well-thank-java-files-provided-us--q6129771

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

Demo.java

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

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

LinkedList.java

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

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

City.java

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

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

LinkedListElement.java

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

Could someone please help me with this? 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 The first activity involves modifying the sort_OutOfPlace() method in the LinkedList class: //Sort the current list and return it as a new list public LinkedList sort_OutOfPLace() { } Currently, this method sorts the list of cities by name (alphabetically). You need to change this method and if necessary change the City and LinkedListElement classes so that you can sort the list of cities by population (largest -> smallest). Your changes should keep the LinkedList class generic and able to sort other data (e.g., Strings). [Note: the cities should be sorted with the largest population first!] Activity 2: In-Place Sorting can be found here:

Explanation / Answer

just change these functions:

public LinkedList sort_OutOfPlace() {
//Check the special case of an empty list
//if the list is empty we return a new empty list
if (isEmpty()) {
return (new LinkedList());
}
  
//General case -- the list is not empty
//step 1: create a new list and add the smallest element to the list
LinkedList newList = new LinkedList();
LinkedListElement nextBiggestElement = findBiggest();
newList.append(nextBiggestElement.content);
LinkedListElement currElement;
LinkedListElement nextSmaller;
while (nextBiggestElement != null) {
currElement = first;
nextSmaller = null;
nextSmaller = findNextSmallest(nextBiggestElement, currElement,
nextSmaller);
if (nextSmaller != null) {
newList.append(nextSmaller.content);   
}
nextBiggestElement = nextSmaller;
}   

return newList;
}

private LinkedListElement findNextSmallest(
LinkedListElement nextBiggestElement,
LinkedListElement currElement, LinkedListElement nextSmaller) {
while (currElement != null) {
//Check if currElement is bigger than smallest element
if (currElement.content.getPopulation() <
nextBiggestElement.content.getPopulation()) {
//Check if currElement is smaller than next bigger
if (nextSmaller == null) {
nextSmaller = currElement;   
}
else if (currElement.content.getPopulation() >
nextBigger.content.getPopulation()) {
nextSmaller = currElement;
}
}
currElement = currElement.next;
}
return nextSmaller;
}

private LinkedListElement findBiggest() {
//Find smallest
LinkedListElement currElement = first;
LinkedListElement newElement = null;
  
while (currElement != null) {
if (newElement == null) {
newElement = currElement;
} else {
if (currElement.content.getPopulation() >
newElement.content.getPopulation()) {
newElement = currElement;
}
}
currElement = currElement.next;
}
return newElement;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote