
In java
Implement a sort method
public void sort()
Implement any sort
See the image for correct output.
Given files:
Demo3.java
public class Demo3 {
public static void main(String[] args) {
MyLinkedList<String> list = new MyLinkedList<>();
list.add("E");
list.add("A");
list.add("D");
list.add("B");
list.add("C");
System.out.println("Small data set");
System.out.println(list);
System.out.println("Sort");
list.sort();
System.out.println(list);
System.out.println("Clearing");
list.clear();
System.out.println(list);
System.out.println("Building list");
TestBench.addToList(list);
System.out.println(list);
System.out.println("Shuffle 1");
list.shuffle(150);
System.out.println(list);
System.out.println("Shuffle 2");
list.shuffle(250);
System.out.println(list);
System.out.println("Sort");
list.sort();
System.out.println(list);
System.out.println("Adding more elements and shuffling");
TestBench.addToList(list);
TestBench.addToList(list);
list.shuffle(250);
System.out.println(list);
System.out.println("Sorting");
list.sort();
System.out.println(list);
}
}
TestBench.java
![Test Case 1
Small data set \n
[Е, А, D, B, с]\n
Sort n
[А, В, с, D, E]|n
Clearing n
[ ] n
Building list \n
[А, в, с, D, Е, F, G, H, І, J, к, L, м, N, о, Р, Q, R, S, т, U, v, w, х, Y, 2]|\n|
Shuffle 1\n
ГЕ, с, 9, N, Z, J, I, Y, Р, L, E, M, о, к, D, н, и, х, G, w, A, V, т, R, В, S]n
Shuffle 2 \n
[Е, Ј, R, N, I, F, Q, х, W, V, U, G, D, A, H, т, Ү, Р, L, s, C, Z, 0, в, к, м]| n
Sort In
[А, В, с, D, Е, F, G, H, І, J, к, L, м, N, о, Р, Q, R, S, т, U, v, w, х, Y, 2]|m
Adding more elements and shuffling In
[к, т, х, D, J, к, с, R, z, н, Y, V, L, U, A, M, L, w, т, G, U, s, E, Y, C, J, R, D, Z, D, Q, 0, V, s, т, в, S, Y, N, L, W, M, N, Е, W, H, Е, J, А, Р, в, х, Р, Q, Q. к, F, В, I, F, N, V, о, F, н, Z, I, U, с, Р, х, 0, G, I, A, м,
R, G] \n
Sorting In
[А, А, А, В, в, в, с, с, с, D, D, D, E, E, Е, F, F, F, G, G, G, н, н, н, I, І, І, Ј, , 3, к, к, к, L, L, L, м, м, м, N, N, N, о, о, о, р, Р, Р, 0, 0, 0. R, R, R, S, S, S, т, т, т, и, и, U, v, v, v, w, w, м, х, х, х, у, Ү, Ү, Z,
z, z] \n
s и](https://content.bartleby.com/qna-images/question/4e8a92e6-ccd1-4b67-b436-479a3fd34a6c/1682519f-9c5b-4107-837a-36b99c1b8e84/kldt0wl_thumbnail.png)

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- Trace insertion sort for list ={18,57,8,89,7}arrow_forwardIn Java list all the values of the array after the function is called A. static void Fun(int[][]list){ int temp=list[1][2]; list[1][2]=list[0][2]; list[0][2]=temp; } public static void main(String[] args) { int [][]arr={{10,20,30},{100,200,300}}; Fun(arr); } 10,20,30,300 B. static void Fun(int[]list) { list[3]=5;} public static void main(String[] args) { int []arr={5,6,7,9}; Fun(arr); } C. static void Fun(int[][]list){ list[1][0]=0;} public static void main(String[] args) { int [][]arr={{-2,-3,-4},{5,6,7,9}}; Fun(arr); }arrow_forwardJAVA The following code for InsertionSort is given to us by the textbook. Trace the code stepby step using the array[55, 22, 77, 99, 66, 33, 11]on a piece of paper or using a Word document. If the code has errors, correct it and make itwork.public static void insertionSort(double[] list) {for (int i = 1; i < list.length; i++) {/** insert list[i] into a sorted sublist list[0..i-1] so thatlist[0..i] is sorted. */double currentElement = list[i];int k;for (k = i - 1; k >= 0 && list[k] > currentElement; k--) {list[k + 1] = list[k];}// Insert the current element into list[k+1]list[k + 1] = currentElement;}}arrow_forward
- Computer Science PLEASE HELP TO CONVERT THIS FOR LOOP TO FOREACH LOOP using System;using System.Collections.Generic; namespace SwinAdventure{public class IdentifierableObject{//field ,datapublic List<string> Identifier = new List<string>(); //constructorpublic IdentifierableObject(string[] ident){for (int i = 0; i < ident.Length; i++){Identifier.Add(ident[i]);}} // Methodpublic void AddIdentifier(string id){Identifier.Add(id.ToLower());} // propertiespublic string FirstID{get{return Identifier[0];}} public bool AreYou(string id){for (int i = 0; i < Identifier.Count; i++){if (Identifier[i] == id.ToLower()){return true;} }return false;}}}arrow_forwardvoid func(vector<string>& names){ sort(names.begin(), names.end()); //(a) for(int i = names.size() - 1; i > 0; --i){. //(b) if(names[i] == names[i - 1]){ names[i] = move(names.back()); names.pop_back(); } } } What are the reasons or consequences for the programmer’s choice to loop backwards in the line marked (b), and under what circumstances would the algorithm behave differently if that line were replaced with: for (int i = 1; i < names.size(); ++i) ? What would change?arrow_forwardCode debug JAVA import java.util.ArrayList;public class ArrayList {public static ArrayList<Integer> reverse(ArrayList<Integer> list) {for (int i = 0; i < list.size(); i++) {System.out.println(list);}public static ArrayList<Integer> getReverse(ArrayList<Integer> list){for (int index = 0; index < list.size() / 2; index++) {int temp = list.get(index);list.set(index, list.get(list.size() - index - 1));//swaplist.set(list.size() - index - 1, temp); //swap}return list;}}public static void main(String[] args) {ArrayList<Integer> list = new ArrayList<>();list.add(1);list.add(2);list.add(3);System.out.println("Original elements : " + list);System.out.println("Reversed elements : " + getReverse(list));}}arrow_forward
- java In this assignment you will swap a position in an array list with another. swap() gets 3 arguments, an Arraylist, a position, and another position to swap with. Example swap(["one","two","three"],0,2) returns:["three","two","one"] public static ArrayList<String> swap(ArrayList<String> list,int pos1,int pos2) public static void main(String[] args) { Scanner in = new Scanner(System.in); int size = in.nextInt(); int pos1 = in.nextInt(); int pos2 = in.nextInt(); ArrayList<String> list = new ArrayList<>(); for(int i=0; i < size; i++) { list.add(in.next()); } System.out.println(swap(list, pos1, pos2)); } }arrow_forwardPython’s list method sort includes the keyword argument reverse, whose defaultvalue is False. The programmer can override this value to sort a list in descendingorder. Modify the selectionSort function so that it allowsthe programmer to supply this additional argument to redirect the sort. selectionSort function: def selectionSort(lyst, profiler):i = 0 while i < len(lyst) - 1:minIndex = ij = i + 1 while j < len(lyst):profiler.comparison() # Countif lyst[j] < lyst[minIndex]:minIndex = jj += 1 if minIndex != i:swap(lyst, minIndex, i, profiler)i += 1 def swap(lyst, i, j, profiler):"""Exchanges the elements at positions i and j."""profiler.exchange() # Counttemp = lyst[i]lyst[i] = lyst[j]lyst[j] = temp Use this template in Python to modify the function above: def selection_sort(input_list, reverse):sorted_list = []#TODO: Your work here# Return sorted_listreturn sorted_listif __name__ == "__main__":my_list = [1, 2, 3, 4, 5]print(selection_sort(my_list, True)) # Correct Output: [5,…arrow_forwardQuestion v .Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





