Assignment 3: Mergesort & Quicksort(10 points)

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.

Input

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.

Files We Give You

Use the Makefile from Assignment 1 as a guide and adjust it as needed for this assignment.

Files You Must Write

You will write two files for this assignment:

The two files will obviously contain some identical code.

Output

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$

Hints

Last modified: 2020-09-12 20:02:52 CDT