Introduction
For your second programming assignment, you are to implement a sorting algorithm using a stack and two queues. Your program will check both real and decimal numbers as well as strings.
I/O
Your executable must be named sqsort. The executable reads in a series of only string, decimal, or real numbers, either from
a file or from stdin, and will produce, on stdout, the list of numbers as they are processed Here is an example invocation:
$ echo \"2 4 5 3 1\" > items
$ sqsort -d items
[2, 4, 5, 3, 1]
[5, 4, 2, 3, 1]
[5, 4, 3, 2, 1]
$
where $ is the system prompt. The file to be processed (items in the example) is a free-format text file. That is, the potential values within are separated by arbitrary amounts of whitespace (i.e. spaces, tabs, and newlines) and every line ends with a newline. If a file name is not given, input is to be read from the keyboard:
$ sqsort -d
"goodbye"             "c is the best"
             "hello"
       "please compile"
                           "0"
["goodbye", "c is the best", "hello", "please compile", "0"]
["please compile", "goodbye", "hello, "c is the best", "0"]
["please compile", "hello", "goodbye", "c is the best", "0"]
$
Input is ended by entering a ^D character.
The executable must handle the following options:

option             example                         action

--------------------------------------------------------------------------------------------------------------

-v                   sqsort -v                          give author’s name and exit
[-d,-r,-s]          sqsort -d FILENAME           print the steps of each pass of the algorithm
                                                           found in FILENAME
sqsort [-d,-r,-s]                                      print the steaps of each pass of the algorithm
                                                           read in from stdin
Here are some example invocations using options:
$ sqsort -v
Jeffrey A. Robinson
$ sqsort -r
1.5 2.6 3.8 1.9
[1.5, 2.6, 3.8, 1.9]
[3.8, 2.6, 1.5, 1.9]
[3.8, 2.6, 1.9, 1.5]
$
Reading the input
You may find the Art and Science of Programming - C Edition scanner to be useful for this task:
wget troll.cs.ua.edu/ACP-C/scanner.c
wget troll.cs.ua.edu/ACP-C/scanner.h
You can use this to read in integers, reals, or string values. Note that a token is not a string. Using scanf, fscanf, gets, or other equivalent functions is forbidden and will result in a penalty if used.
Error checking
The only error checking you must perform is detecting the valid use of flags.
$ sqsort -q
unknown flag 'q', valid flags are -d, -r, -s, and -v
$
After printing the error message, you should exit the program. Other than this one exception, your program will only be tested with valid input.
Implementation details
You must follow the C programming style guide for this project: http://beastie.cs.ua.edu/cs201/cstyle.html.
Compilation details
You must implement your sorting algorithm in C99. You must provide a makefile which responds properly to the commands:
make
make test
make clean
The make command compiles your program, which should compile cleanly with no warnings or errors at the highest level of error checking (the -Wall option for gcc). The make test command should test your program and the make clean command should remove object files and the executable. Here are examples (your files may differ in number and name):
$ make clean
rm -f scanner.o value.o node.o queue.o stack.o bst.o sqsort.o sqsort
$ make
gcc -Wall -std=c99 -c -g scanner.c
gcc -Wall -std=c99 -c -g value.c
gcc -Wall -std=c99 -c -g node.c
gcc -Wall -std=c99 -c -g queue.c
gcc -Wall -std=c99 -c -g stack.c
gcc -Wall -std=c99 -c -g bst.c
gcc -Wall -std=c99 -c -g sqsort.c
gcc -Wall -std=c99 scanner.o value.o node.o queue.o stack.o bst.o sqsort.o -o sqsort
$ make
make: `sqsort' is up to date.
$ make test
sqsort -d mytestfile
[1, 2, 3, 4, 5, 6]
[6, 5, 4, 3, 2, 1]
$
The compilation command must name the executable sqsort (not sqsort.exe for you Cygwin users). The You may develop on any system you wish but your program will be compiled and tested on a Linux system. Only the most foolish students would not thoroughly test their implementations on a Linux system before submission.
Note: depending on where you develop your code, uninitialized variables may have a tendency to start with a value of zero. Thus, a program with uninitialized variables may work on your system but fail when I run it. I won’t care, as you are mature enough not to have uninitialized variables. You may have other errors as well that do not reveal themselves until run on my system. Again, that’s not my problem. If I am feeling generous and have the time, I may figure out where your error is and,
perhaps, give you a few meager points back, but don’t depend on it.
Documentation
All code you hand in must be attributed to its authors. Comment sparingly but well. Do explain the purpose of your program. Do not explain obvious code. If code is not obvious, consider rewriting the code rather than explaining what is going on through comments.
Grading
TODO
Submission
To submit assignments, you need to install the submit system.
• linux, windows 10 bash, and cygwin instructions
• mac instructions
You will hand in (electronically) your code for the preliminary assessment and for final testing with the command:
submit cs201 lusth assign1
Make sure you are in the same directory as your makefile when submitting. The submit program will bundle up all the files in your current directory and ship them to me. Thus it is very important that only the source code and any testing files be in your directory. This includes subdirectories as well since all the files in any subdirectories will also be shipped to me. I will deduct points if you submit object files or executables, so be careful. You may submit as many times as you want before the deadline; new submissions replace old submissions. Old submissions are stored and can be used for backup.