Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1- Write a program that takes filename, count, minimum and maximum values from the user and writes count number of random integers between minimum and

1- Write a program that takes filename, count, minimum and maximum values from the user and writes count number of random integers between minimum and maximum values to the file specified by the filename. The resulting file should have a random integer at each line, as shown below: Your program should expect command-line arguments as given below: ProgramName filename count min max Your program should generate different random integers at each execution. After that write a program that compares execution times for the sort algorithms: Quick-sort, Selection-sort, Shell-sort and Bubble-sort (improved version). Some of these algorithms are already available in the codes section of the Blackboard. For others, you can refer to books or internet.

In order to compare the algorithms, first create three files having 1,000, 10,000, and 100,000 random integers, using the program you have coded in the previous question. You can name the files as 1000, 10000, and 100000, respectively.

Your program should read the contents of the files into an array one by one (i.e. one file at a time), and sort the array using the algorithms listed above. You will measure the time elapsed by each algorithm and print it on the screen, as shown below. You do NOT need to write the sorted content back to files.

 quickSort 1000 0.001 
10000 0.003 100000 0.026 
shellSort 0.000 0.004 0.039 
bubbleSort 0.009 0.356 38.967 
selectionSort 0.003 0.138 13.739 

Each sort algorithm should be coded as a function having identical signature with the other sort functions. For example, the algorithms can be declared as given below:

 void quickSort(int arr[], int count); void shellSort (int arr[], int count); void bubbleSort(int arr[], int count); void selectionSort(int arr[], int count); 

Since sorting algorithms change the input array, you should not pass the array that is read from the file directly to the sorting function, but make a copy first and pass that copy to the sorting function. That way the sorting algorithms will work on the same input array.

Your program should define a function pointer array, pointing to the sort functions defined. That way you can call all sort functions with a for loop. For instance, you can use the definitions given below:

void (*pFunctions[FUNC_COUNT])(int *,int) = {quickSort, shellSort, bubbleSort, selectionSort};

Defining the names of the functions in an array may also be useful:

char *sFunctions[FUNC_COUNT] = {"quickSort", "shellSort", "bubbleSort", "selectionSort"};

Your program should check whether all the algorithms create the same sorted array. For this you can take the result of one algorithm and compare it with the previous result you do not need to compare all the results with each other. If one of the results does not agree with others, you should print an appropriate message on the console.

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_2

Step: 3

blur-text-image_3

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

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions

Question

The Nature of Nonverbal Communication

Answered: 1 week ago

Question

Functions of Nonverbal Communication

Answered: 1 week ago

Question

Nonverbal Communication Codes

Answered: 1 week ago