Question
JAVA QUESTION An array is said to be sorted if its elements are in either increasing or decreasing order. One way the selection sort algorithm
JAVA QUESTION
An array is said to be sorted if its elements are in either increasing or decreasing order. One way the selection sort algorithm works is by repeatedly taking the lowest element from an array and adding it to a new array, so that all the elements in the new array are sorted from lowest to highest. Create a SelectionSort class with a constructor that has an int array parameter, member variables originalArray and sortedArray, public method display() that displays the contents of the sorted array, private methods sort() that populates a new array with the elements of the original array in order from lowest to highest, and findLowest() that returns the index of the element containing the lowest value. Hint: Since elements of an array cannot actually be removed an element can be set to a very high value after determining its value is the lowest. Create client code SortedArray, which tests the SelectionSort class. Use the pseudocode below when implementing the SortedArray client code:
int[] myNums; SelectionSort sortedArray; prompt user for the number of values to populate array with myNums = new int[values]; populate array with random integers between 0 and 100 display contents of original array sortedArray = new SelectionSort(myNums); sortedArray.display();
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started