| CS 311 Fall 2009 > Assignment 7 |
Assignment 7 is due at 5 p.m. Tuesday, November 24. It is worth 25 points.
This is a group assignment. Please work in a group of 2 or 3. Each group only needs to turn in a single copy of the assignment. Under normal circumstances, each will receive the same grade on the assignment.
E-mail
answers to the exercises below to
ffggc@uaf.edu,
using the subject
“DA7”.
bstree.h, from Exercise A.
This file (or an archive file containing it)
should be attached to your e-mail message.In this exercise, you will write a simple Binary Search Tree. It will be able to retrieve and insert by key, do the three standard traversals, and copy itself.
Implement a C++ class template that manages a Binary Search Tree holding keys without associated data. The type of key should be specified by the client code. Be sure to follow the coding standards. All standards apply.
BSTree”, so that, for example, a BSTree with key type int
would be declared as a BSTree<int>.bstree.h.
Since this is a template, there should be no associated source file.operator<.BSTree must include the following public member functions,
and no others:
size.
No parameters, returns std::size_t.
Returns the number of keys stored in the tree.empty.
No parameters, returns bool.
Returns true if the size of the tree is zero.
Must be constant-time.
clear.
No parameters, returns nothing.
Removes all keys from the tree,
resulting in an empty tree.retrieve.
Given a key, returns a bool.
Returns true if a key equivalent to the given key
is in the tree.insert.
Given a key, returns a bool.
If a key equivalent to the given key is in the tree already,
then returns true, leaving the tree unchanged.
Otherwise, inserts the given key into the tree,
and returns false.preorderTraverse,
inorderTraverse, postorderTraverse.
Given an output iterator,
return nothing.
Does “*iter++ = key;” for each key in the tree, with iter being the given iterator.
The functions traverse the keys in the order given by
the preorder, inorder, and postorder traversals of the tree,
respectively.std::size_t,
and functions, like std::swap.)
I have written a test program:
bstree_test.cpp.
If you compile and run your package with this program (unmodified!), then it will test
whether your code works properly.
Do not turn in bstree_test.cpp.
CS 311 Fall 2009: Assignment 7 /
Updated: 23 Nov 2009 /
Glenn G. Chappell /
ffggc@uaf.edu
|
|