Assignment 7, Due at 11:59pm, Sunday Nov 16

Forewords

This assignment looks deceptively simple but it might take you any where from a few hours to infinity depending on how well you really understand recursion. Like all of the previous assignments in this course, this assignment does not require a lot of coding. (When I taught CSE 489/589, the programming projects required something like 3000-5000 lines of codes. The assignments we have seen thus far involved about 100-200 lines top.) But I strongly encourage you to think deeply "on paper" before delving into writing the code. No amount of "hacking around" is going to lead you anywhere if you don't know what you're doing on this assignment.

By now, I have discussed everything you needed to know to do this assignment. In particular, the assignment is not complex language-wise. The difficulty you will face is definitely not on the C++ side. There is an article by Joel Spolsky (co-founder of stackoverflow) that is a bit controversial, but well worth a read. I strongly recommend it.

Thus far looking things up on Google has been permitted. However, for this particular assignment please do not read/copy/modify anybody's code from any source. If the plagiarim software detects so, zero point shall be given (and F for the course for the second-time offenders). You are welcome to discuss "on paper", "on the board" with classmates!

Objectives

The Setting

We will develop a program that does the following. The program takes commands from users, as usual; the following commands are supported:

  • I have written program called hqn-printtree following the above specification and compiled it under timberlake. You can download and run it (in timberlake) to see how it is supposed to work. To download it, use wget as usual:
    wget http://www.cse.buffalo.edu/~hungngo/classes/2014/Fall/250/assignments/hqn-printtree
    chmod 700 hqn-printtree
    
    Here is a sample run of the program:
    UB Tree Program. Version 0.7
     Author: Hung Q. Ngo
     Report bugs to hungngo@buffalo.edu
    > newtree
    Enter the preorder and inorder sequences for your tree, use unique names
    Preor. seq.: root thisisverylong short 34 longer aaaaaaaaa bbbbbbb c
    Inor. seq. : thisisverylong short root aaaaaaaaa longer bbbbbbb 34 c
    > inorder
    thisisverylong short root aaaaaaaaa longer bbbbbbb 34 c 
    > postorder
    short thisisverylong aaaaaaaaa bbbbbbb longer c 34 root 
    > levelorder
    root thisisverylong 34 short longer c aaaaaaaaa bbbbbbb 
    
    > preorder
    root thisisverylong short 34 longer aaaaaaaaa bbbbbbb c 
    > ver
    root
    |__34
    |  |__c
    |  |
    |  |__longer
    |     |__bbbbbbb
    |     |
    |     |__aaaaaaaaa
    |
    |__thisisverylong
       |__short
       |
       |__x
    
    > hor
    root__________________
    |                     \
    thisisverylong         34___________________
    |             \        |                    \
    x              short   longer_____           c
                           |          \
                           aaaaaaaaa   bbbbbbb
    
    > sym
               _________root__________
              /                       \
      thisisverylong                __34__
     /              \              /      \
    x              short       longer      c
                              /      \
                         aaaaaaaaa bbbbbbb
    
    > newtree 
    Enter the preorder and inorder sequences for your tree, use unique names
    Preor. seq.: a b c  
    Inor. seq. : a b c
    > ver
    a
    |__b
    |  |__c
    |  |
    |  |__x
    |
    |__x
    
    > hor
    a
    |\
    x b
      |\
      x c
    
    > sym
      a
     / \
    x   b
       / \
      x   c
    
    >
    
    Note that NULL nodes are represented by an x, so you can assume the input does not have any node whose payload is x. If a node has two NULL children then we don't print the two x's. A NULL child is only printed when the node has at least one non-NULL child.

    What to do

    The real task: as in many of the previous assignments, you are provided with the skeleton of the program with a few blank functions. Your task is to understand the code and implement the three empty-body functions. To download the code base, click here, or from your timberlake account type

    wget http://www.cse.buffalo.edu/~hungngo/classes/2014/Fall/250/assignments/printtree.tar.gz
    gunzip printtree.tar.gz
    tar -xvf printtree.tar
    

    In the printtree directory you will find the source codes for the program. All commands are already implemented except for three commands ver, hor, and sym. Your job is to do the following:

    1. Carefully read and understand the source codes.
    2. Implement the three member functions vertical(), horizontal(), and symmetric(), left blank in BinaryTree.cpp.
    3. You can modify two files: BinaryTree.h and BinaryTree.cpp. In particular, feel free to add more functions or data members to the BinaryTree class. (You will likely have to!)
    When you submit your assignment, you will only submit two files: BinaryTree.cpp and BinaryTree.h. We will copy this file to a directory containing all other files and compile and grade. Don't modify any other files. This is to illustrate how you work within a code base that someone else has written. ver is much easier, so it would be wise to implement that first. Type make to compile the program and all commands will work. For ver, hor and sym, a line TBD will be printed.

    How to submit

    submit_cse250 BinaryTree.cpp
    submit_cse250 BinaryTree.h
    
    Note that the last line only works if you logged in to your CSE account and the files are there. All previous things can be done at home, as long as you remember to upload the final file to your CSE account and run the submit script from there.

    Grading

    Maximum score of 100 points, broken down as follows.