Write two short programs that implement the recursive Quicksort and Merge Sort algorithms. Each of these programs will read up to 1000 integers, sort them, and then print them in a formatted fashion.
Each program you write must read from standard input using input redirection.
Your programs must properly handle cases where there are zero or more lines of text, each containing zero or more integer numbers separated by whitespace.
We may test your programs with input that containing zero integers, exactly 1000 integers, and several with in-between quantities. You may assume that the input data will only contain valid integer values.
It is your own responsibility to create a suitable set of test data for this assignment.
Use the Makefile
from Assignment 1 as a guide and adjust it as needed for this assignment.
You will write two files for this assignment:
quick_sort.cpp
- This file must contain your recursive implementation of the
quicksort algorthm.merge_sort.cpp
- This file must contain your recursive implementation of the
merge sort algorthm.The two files will obviously contain some identical code.
The output must print 8 sorted numbers per line (of course the last line may have less than 8 numbers), nicely aligned in columns. Numbers must be right-aligned. Use the setw
manipulator to pad numbers with leading spaces.
DO NOT print a space after the last number on the lines and the newline character.
DO NOT print any blank lines.
Given suitable test data, the output must look like this:
z123456@turing:~/csci501/Assign3$ ./quick_sort < random6.txt 19 61 75 88 90 98 z123456@turing:~/csci501/Assign1$
z123456@turing:~/csci501/Assign3$ ./merge_sort < random16.txt 7 15 15 20 30 37 42 52 53 56 58 63 65 74 78 89 z123456@turing:~/csci501/Assign1$
z123456@turing:~/csci501/Assign3$ ./quick_sort < random25.txt 1 23 106 127 147 148 157 208 239 265 282 483 561 576 579 677 753 853 879 911 945 959 965 978 982 z123456@turing:~/csci501/Assign3$
Note that your programs must always supply a newline character at the end of each line, even if the last line does not contain 8 numbers. In other words, after running your program, the Unix prompt must always appear in the leftmost column of the screen. Output that looks like this is incorrect:
z123456@turing:~/csci501/Assign3$ ./quick_sort < random6.txt 19 61 75 88 90 98z123456@turing:~/csci501/Assign3$
This assignment has a great deal in common with Assignment 1, particularly when it comes to reading the input and printing the output. You should approach this assignment in a similar fashion to Assignment 1 - start by working on just one of the two files, make sure that you can read and print the unsorted output, then implement the sorting algorithm for that file.
After you have one algorithm working, proceed to the other one.
Use the smaller data files during your initial testing and debugging, but make sure that you test your programs with some of the larger data sets as well.
Last modified: 2020-09-12 20:02:52 CDT