Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. (5 points) Write two functions one to sort an integer array in descending, i.e, large to small, order and the other to another array

image text in transcribed
3. (5 points) Write two functions one to sort an integer array in descending, i.e, large to small, order and the other to another array in descending order. Sorting is done by implementing the selection sort algorithm in Chapter 7 (see below for hints) with minor merge two arrays and store them in modification, i.e., search for the index of the largest element instead of the smallest. You cannot use the C* Ibrary function sort Then you will write a test driver, ie, the mainO function that reads in two integer arrays of maximum size 10 from the console and then outputs the merged array, which contains the sorted numbers, using the two functions created above. The sorted array will be of maximum size 20. You should be able to change the maximum size of the arrays by changing only one globally defined constant. Hint on selection sort: The array is imaginarily divided into two subarrays: the sorted one and unsorted one. Let the length of the array be len. Initially, the sorted subarray is empty and the unsorted subarray contains the whole array. The selection sort iterates through the following steps with array indices from 0 to (len-1), using i to store the index: i. ii. Find out the largest array element from i to (len-1) and use 1g to store the index of the largest number. b) 9 c) Swap the array[i] with array[1g] at this point, the sorted part contains from array[0] to array[1 ], and the unsorted from array( 1+1] to array[len-1] i. e) ifi

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

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

Database programming with Java ( SQLite )

Answered: 1 week ago