Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C progrram, sort.c, which (1) prompt for an input of opration selection: 0, for correctness testing, 1 for performance testing, 2 for exit;

Write a C progrram, sort.c, which (1) prompt for an input of opration selection: 0, for correctness testing, 1 for performance testing, 2 for exit; In operation 0,

(2) randomly generate 10 positive integers with value between 1 and 100, and store them in an array a[],

(3) copy array a[] to array b[], sort array b[] in increasing order by selection sort algorithm, print array b[] in proper format.

(4) copy a[] to array b[], sort array b[] by quick sort algorithm, output b[].The quick sort algorithm, also known as partition-exchange sort, is a fast sorting algorithm, serving as a systematic method for placing the elements of an array in order. You may refer to the following website to know how it works, https://www.algolist.net/Algorithms/Sorting/Selection_sort http://www.algolist.net/Algorithms/Sorting/Quicksort

(5) calculate the average of those numbers in array and print the average in proper format In operation 1,

(6) it randomly generates 50000 positive integer with value between 1 and 50000, and hold them into array a[],

(7) copy a[] to array b[], sort array b[] by selection sort, get and output the sorting time,

(8) copy a[] to b[], and sort array b[] by quick sort algorithm, output the sorting time.

, (9)In operation 2 quit and exit the program Requirements: you need to write C functions for printing user interface, get the operation selection, printing array, selection sort and quick sort. Note that you must use pointers instead of index in array operations.

0 -- correctness testing

1 -- performance testing

2 -- quit

Suppose input 0 (Assuming the randomly generated array is 89 67 77 24 4 44 15 45 58 85) Randomly generated array of length 10 is 89 67 77 24 4 44 15 45 58 85 sorted by selection sort: 4 15 24 44 45 58 67 77 85 89 sorted by quick sort: 4 15 24 44 45 58 67 77 85 89 Average is:50.80 Choose an operation: 0 -- correctness testing 1 -- performance testing 2 -- quit

Suppose input 1 It takes 3.000000 seconds to sort the array by selection sort. It takes 0.000000 seconds to sort the array by quick sort Choose an operation: 0 -- correctness testing 1 -- performance testing

2 -- quit Suppose input 2 The program exits.

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

Students also viewed these Databases questions