Ashley P.

asked • 05/11/20

Selection Sort - Java

Write a Java program to implement the selection sort algorithm in Java, input the following array and display the sorted on the screen. Write a function selectionsort(Arr,N), which sort the array Arr with N elements.


Sample data:       H,S,A,F,R,P,E,C,Z,W,G,J,B,Q,L


1 Expert Answer

By:

Ashley P.

Could you tell me why you used a private class particularly? Can I instated use a public class? And the question says to write a function in the form selectionsort(Arr, N). But java won't let you use that exact format for parameters where we define the method. Instead is it incorrect if I define parameters the way you've defined it?
Report

05/12/20

Istvan S.

tutor
The class is actually public (i.e. "public class SelectionSort"), the sort method is private (i.e. private static void sort..). You can always make the sort method public if you want to access it from outside of this class. My example followed the Java naming rules and conventions: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html Based on the naming convention the method and variable names are written using camel case, so instead of "selectionsort", the method name should be written as "selectionSort" and they should start with lowercase letter, therefore my example used "arr" instead "Arr" and "n" instead of "N". (The code will work with the original names from the question though as long as you change all the references in the implementation accordingly).
Report

05/12/20

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.