Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

} // [lp] output: an array of doubles b. // [4p] Gets an array that starts at a[m] and stops at a[n], and also

image text in transcribedimage text in transcribed

} // [lp] output: an array of doubles "b". // [4p] Gets an array that starts at a[m] and stops at a[n], and also includes all of the elements in between (in their original order). In other words, this function returns the input array "a", but only from index "m" up to (and including) index "n". // HINT: The length of the output array "b" is n m + 1. // Erase this line and put your fromTo() subroutine here. // // // indexOfMax() // // [lp] input an array of doubles. // [1p] output: an integer. // [6p] Returns the INDEX of the maximal element of an array. // Erase this line and put your indexOfMax() subroutine here. // swap() // // [3p] input: two integers "m" and "n", and an array of doubles "a". // [lp] output: an array of doubles "a". // // [4p] Interchanges the elements a[m] and a[n], so that a[m] is where a[n] // used to be, and a[n] is where a[m] used to be. // HINT: You will need to define a temporary variable in order to // interchange the two elements of the array. // Erase this line and put your swap() subroutine here. import java.util.Arrays; public class FinalExam { // main() // [2p] Creates an array of five random doubles between 0 and 10. // [2p] Prints the array to standard output (HINT: use Arrays.toString()). // [2p] Sorts the array using the selectionSort() function below. // [2p] Prints the sorted array to standard output. // Erase this line and put your main() subroutine here. // selectionSort() // [1p] input an array of doubles "a". // [1p] output: an array of doubles "a". // // // [6p] Uses the functions fromTo(), indexOfMax(), and swap() to execute a Selection Sort, in which the largest element is repeatedly moved to the end of the array, and the largest index under consideration is reduced by one. // // // HINT: You may consult section 7.4.4 in our textbook, but do not simply // copy the code from that section. Your implementation of selectionSort() // must call the functions fromTo(), indexOfMax(), and swap() to receive // points. // Erase this line and put your selectionSort() subroutine here. // fromTo() // [3p] input: two integers "m" and "n", and an array of doubles "a". // [1p] output: an array of doubles "b"." //

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microeconomics An Intuitive Approach with Calculus

Authors: Thomas Nechyba

1st edition

538453257, 978-0538453257

More Books

Students also viewed these Programming questions

Question

Differentiate among the types of clinical interviews.

Answered: 1 week ago