For this lab, you are welcome to get technical help from another student on how to use or install any of the tools involved. You may also get syntax help on C. You may not, however, get help on the algorithmic portion of the exercise outside of office hours or piazza questions to TAs or instructors.
$ cd CNET-cs152-win-17 $ mkdir hw7 $ svn add hw7 $ cd hw7
In this warm up, we will build the appropriate functions that we will be using to create and operate on our data structures that together implement our compression technique. The files we will be working with are:
We already have completed the functions contained in word.c, and most of those in bst.c. Now, to complete bst.c, we will be implementing the iterator function. In order to do this effectively, we will be using a linked list once again. However, there is some flexibility in the specific implementation. Provided for us is a header file llist.h, and this file contains several different access methods. It is up to you to choose specifically how you want to utilize this linked list, which effectively is deciding which of the access and insertion functions you wish to choose.
Once you come up with a set that you are planning on using, add a note to the top of your llist.h file indicating which functions you chose and why. Choose wisely!
The functions you can choose from are:
Once this is completed, we will use these functions to implement our iterator defined in bst.h:
This function is an iterator that accesses items in the binary search tree in an in-order traversal. Recall that an inorder traversal requires that all left-subtrees are visited, followed by the root, followed by right subtrees, in that sequence. This is the location where we will leverage our choice of linked-list access mechanism.
An example of an in-order traversal is shown below:
(source: https://en.wikipedia.org/wiki/Tree_traversal#In-order)
In heap.c, we will be implementing two heap functions: insert and remove, along with create() and free(). The creation and free functions are very similar to those for the bst data structure that you implemented in bst.h
At this point we have done the following:
To test for correctness, we can run our set of functions against various input text files. A good testing procedure should include building and printing out a binary search tree sorted alphabetically (printing out via the inorder traversal that we have now implemented), and building a second binary search tree sorted instead by word frequency, and printing out the words again utilizing our new iterator, in descending order by frequency. Next, we can build a min-heap of the words in our text file, and print those out again ordering by frequency count. These should agree with one another!
$ svn add hw7
mkdir CNET-cs152-win-17/hw7 cp cs152-win-17-duet-0x/hw7/* CNET-cs152-win-17/hw7/* cd CNET-cs152-win-17 svn add hw7
$ svn add *.h *.c Makefile
$ svn commit -m "hw7 warmup complete"