Due: Friday, Nov. 15, by 8am
Last Date to Turn in: Tuesday, Nov. 19 by 8am
40 points
This assignment will use an animation tool called the Xtango animator that runs on X windows. This program will run on any of the Sparc 5's in the clusters.
In your cps100 directory, create a directory called assign5 using the mkdir command. Change into the assign5 directory.
In order to do this assignment you will need to link to the Xtango animator. In your assign5 directory, type
ln -s ~rodger/bin/animator anim
You'll also need to copy the following setup file. Type:
cp ~rodger/bin/setup setup
Each time you login you will need to type "setup" in your assign5 directory to setup the X environment so you can run the Xtango animator.
For the programming problem that follows, you should use the style rules discussed in class, which includes meaningful variable names, indentation, and comments (pre and postconditions) at the top of the file and for each function. Also include your name, date, course, and purpose in a comment at the top of the program.
You are to process and animate the following tree commands.
(where x is an integer). Insert the number x into a binary search tree. If x is to be inserted at a level number greater than 5 or x is a duplicate, then do not insert x. In this case, print an informative message as to why x was not inserted.
(where x and y are integers). Find the lowest common ancestor of x and y in the tree. Any two nodes in a tree have one or more common ancestors. The lowest common ancestor is the one that is closest to the nodes. If one of x and y is not in the tree, print an error message.
At this point, reorganize the data values into a min tree. Each node in a min tree is smaller than the nodes in both its subtrees. You may assume there will be no more insert or find commands entered after mintree is entered.
The reorganized tree must have the same structure as the binary search tree. Reorganizing means you can swap data values that are not in the correct order, but DO NOT tear the tree down and rebuild it from scratch.
Delete the minimum node in the tree. You may assume this command only appears after the mintree command. After the deletion, the tree should still be a mintree.
Sample input and output files are in ~rodger/cps100/assign5. The sample input file does not test the find command, you'll have to create your own data file for this.
Two output files have been created, tree.out and tree2.out (from tree.in and tree2.in). To see what they look like on the animator, type
anim < tree.out
You should slow down the animation by moving the scroll bar on the far right down to the bottom. Then click on the run animation button.
struct Node { int data; Node * left; Node * right; };
tree < data1 > out1
Thus, cin will automatically read in from the file data1, and cout will automatically write to the file out1.
See above for running the animator on your output file.
See the sample input files, tree.in and tree2.in in ~rodger/cps100/assign5
NOTE: These sample files don't show an example of the find command.
Output should be an animation of the tree operations. Output from your program should be suitable for the Xtango animator. See the handout entitled Animator Commands for information on the format of your output.
Your animations do not have to look exactly like mine. Feel free to jazz them up, add more delays, etc. The examples are in color, but you don't have to use color. Using the color black should work on black and white screens.
When your programs compile and produce the correct output, create a "README" file (please use all capital letters). Include your name, the date, and an estimate of how long you worked on the assignment in the "README" file. You must also include a list of names of all those people (students, prof, tas, tutor) with whom you consulted on the assignment. See the rules for collaboration in the CPS 100 syllabus.
To submit your programs electronically type (where file1 file2 ... are all the .cc and .h files needed by your program):
submit100 assign5 README Makefile file1 file2 ...
You should receive a message telling you that the program was submitted correctly. If it doesn't work try typing ~rodger/bin/submit100 in place of submit100 above.