I was wondering if someone could show me how to write up a selection sort code m
ID: 3681161 • Letter: I
Question
I was wondering if someone could show me how to write up a selection sort code methods in Java, given the following pseudocode.
Pseudocode for an In-Place Selection Sort on an Array of Data Start Selection Sort-sort in ascending order (lowest to highest) a[n] is an array with n elements. The data type of the array must be a comparable data type. int spot;// location in the array where we will insert the minimum from the remainder of the list int minimum;//location of the minimum value in the remainder of the list for ( spot=0; spotExplanation / Answer
public class SelectionSort {
public static void selectionSort(int[] a){
int spot;
int minimum;
for(spot=0; spot<a.length; spot++){
minimum = spot;
for(int i=spot+1; i<a.length; i++){
if(a[i] < a[minimum])
minimum = i;
}
// swaping
int temp = a[spot];
a[spot] = a[minimum];
a[minimum] = temp;
}
}
public static void main(String[] args) {
int a[] = {7,1,8,2,9,3,0,4,6,5};
selectionSort(a);
for(int i:a)
System.out.print(i+" ");
}
}
/*
Output:
0 1 2 3 4 5 6 7 8 9
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.