I am not allowed to "brute force" by traversing the entire tree to find these keys. |
So presumably, the smallest would be found by always following the left child, and largest by always following the right child?
This is obviously incorrect as there are no values being passed, but I'm curious as to what I actually type in here as parameters? |
Well, looking at the parameters, you need to pass the tree and 2 ints.
(but should it be in private instead, and if so, why?) |
If it was private, it would have to be called by another member function, and it would no longer be part of the public interface.
On line 257 of binary_tree.h is where I tried implementing my own smallest_key function, and declare it on line 39 in the public section of btree class
|
I think you need to reorganise your files:
1. The file with the main function would be named main.cpp , I like to do this because when there are lots of files it's easy to find.
2. It's evil to put implementation code in header files. If they are included in multiple places .......
3. Put the class definition only into the header file, named directly after the class name.
4. Put the implementation (the function definitions) into the cpp file, named directly after the class name.
Some other things, avoid using
NULL
, use
nullptr
instead - it was invented to get around problems associated with using
NULL
and pointers.
Thoroughly pedantically, a btree is a different thing to a binary tree. It can have more than 2 children.
https://en.wikipedia.org/wiki/B-tree