BTreeNode
class, which contains a lot of useful methods
for manipulating nodes. This allows you to write methods more
abstractly in the BTree
class. The BTree
class contains the methods which you are responsible for writing,
Find()
, Insert()
, and Remove()
.
Both the BTreeNode
and BTree
classes are
templates with two parameters, the first being the type of the key and
the second being the type of the data associated with the key.
For Part I, write pseudocode for the BTree
methods, using
the BTreeNode
operations to help you. You must
hand in your pseudocode in class on the Part I due
date above.
Find()
, Insert()
, and
Remove()
methods for the BTree
class. You
may not change the prototypes for any of these
methods, since they are used as they are currently defined in the
testing module. However, you may (and probably should) add extra
private helper methods. To give you some hints on these, I have left
comments showing the helper methods I used in my implementation. You
should not need to modify any files except Btree.h
and
BTree.cpp
.
To test your program, I have included a sample program which lets
you insert, find, and remove numeric keys with associated strings as
data. For example, you could insert the pair (9430524, "Daniel
Fasulo")
. The program also lets your print your tree to
inspect it for errors. You should be able to put all of the supplied
files into a directory, type make
, and end up with a
program called btree
. To run the program, simply type
btree
; it will then give you a self-explanatory menu of
options.
By the Part II due date, you should turn in all of
the files associated with your project, meaning the implementation
(.cpp) files, the header (.h) files, and the makefile. This includes
the initial code I gave you. As usual, you are responsible for
turning in a hardcopy in class and
performing an electronic turnin using the
turnin
program.
As I mentioned in section, the handling of templates is very compiler-specific. Even if you choose to write your code on some other platform, your final submission must compile and run on the instructional Alphas, sanjuan and orcas.
Insert()
and Find()
methods first, and
the doing the Delete()
method. It is better (from
a grading as well as practical perspective) to have a
functioning program that implements a subset of the
specification than one that does not compile or run at all.
BTreeNode
class aggressively uses assertions
to check the preconditions for its functions. If an assertion
fails (at least on a UNIX computer), the program will halt and
perform a core dump, just as if it had crashed. To use
gdb
to examine the core file (called
core
), you can type
gdb btree coreThis will let you view the program's state when it crashed.