DUE Wednesday, November 22 CS 3100 Programming Assignment #4 Comparing Sort Algorithms Write a program that REPEATEDLY 1) Prompts the user to enter a filename. 2) opens the file 3) reads a comment from the first line 4) reads an integer N from the second line (e.g. N = 1000) 5) reads N integers from the rest of the file, putting them into consecutive locations in an array. 6) Sorts an identical copy of the array using each of the following methods; a. selection sort b. insertion sort c. quick sort d. heap sort 7) Writes the name of the input file 8) Writes the comment from the input file 9) Writes a report of the number of data comparisons, and data moves done in each sort. 10) Asks the user if he/she wishes to continue UNTIL the user wishes NOT to continue. DETAILS: You will probably want to either make the list a value parameter of each sort procedure, or pass in a copy of the original list to each sort. Why? When counting comparisons, count ONLY comparisons of the array contents (the things that are being sorted), not the array indices. For example, "if DATA[J] < DATA[J - 1]" is a comparison to be counted, but "while I < J" is not a comparison to be counted. When counting data moves, count the number of times that an array element is moved from one location to another. Moves to temporary locations should be counted too. For example, a "swap" of the form temp <--- a, a <--- b, b <--- temp is counted as three moves. You can find a lot of sort routine code in chapter 6 of your book and in the cs2500 gopher directory under CourseDisks/DL_Stuff3/sorts.pas, or CourseDisks/DL_Stuff2/sorts.pas. These directories contain code from the 3rd and 2nd editions of the CS 2500 text book authored by Dale and Lilly. DL_Stuff3/sorts.pas does not include a version of insert sort, but DL_Stuff2/sorts.pas does. If you want to include other sorts besides the four I assigned above, go ahead. When you adapt code from a book or course disk, you are responsible to fix any bugs in the code. SAMPLE INPUT and OUTPUT files The examples below should be enough to allow you to figure out what you need to make your program do. Don't believe the counts in the sample output files. They are just made-up numbers that I thought seemed plausible. ------------------- sample inputs ----------------- Here is a sample input file we will call ran1000: This is a random list of 1000 numbers. 1000 233 871 954 23 1245 (... the file continues ... 1000 numbers in all, starting with 233) Here is a sample file we will call ord50: This is an ordered list of 50 numbers. 50 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 ------------------- sample output ----------------- File Name: ran1000 File comment: This is a random list of 1000 numbers. Here are the results of the sorts: compares swaps selection sort 499500 1000 insertion sort 251000 250000 quick sort 12000 6500 heap sort 12450 7453 File Name: ord50 File comment: This is an ordered list of 50 numbers. compares swaps selection sort 1225 50 insertion sort 49 0 quick sort 1250 680 heap sort 290 153 TESTING: Be sure to test your program on large lists (up to 1000 elements), medium size lists, small lists, ordered lists (both ascending and descending order) and unordered lists. Test all possible combinations of these list characteristics. In the header of your program, include a paragraph describing what you learned from writing and testing this program. You may want to write some small programs to generate your input lists. It's very simple to write a program to generate an ordered list of any desired size. I have included a copy of makerand.c in this directory. Read the file. You can use it to generate undordered lists. You probably should modify makerand.c a little, so that it generates singletons instead of pairs.