For this assignment, you will implement natural mergesort. Rather than using
a menu-driven program or prompting the user for the filename, the user will
provide the filename on the command line. The advantage of this method is
that it requires no further interaction from the user after they type the
command. Thus, the user can easily automate the program if they desire. The
command line arguments are parsed by changing the main()
function
to one that takes parameters. The parameters are an integer that stores the
number of command line arguments and an array of C-strings that contain the
actual arguments. Refer to cli_example.cpp for
an example of how to get two filenames from the command line by modifying
main()
. To run the example, issue the following commands:
g++ -o cli_example cli_example.cpp ./cli_example ./cli_example file1 file2You will be writing one main program that, like cli_example, takes two command line arguments. The first argument will be the input filename. The second argument will be the output filename. If you fail to open either file, print an error message and exit. You will also need two temporary output filenames to use during spliting and merging. Use something unique like a string of random characters so that you will not overwrite an actual file ("file1" or "tmp1" is not unique enough).
Your program will then perform the natural mergesort on the input file, using the method stated in the book and discussed in class. At the end of the program, the input filename should be untouched (containing the elements in the original order) and the output filename will contain the sorted elements.
Sample input files:
Email your completed file to me.