/*********************************************************************** * binarytree.h * * Header file for a simple inplementation of a binary tree * * Written by Paul Bonamy - 24 January 2010 * Tweaked for use as a debugging quiz - 3 June 2010 ************************************************************************/ #ifndef BINARYTREE_H #define BINARYTREE_H /*********************************************************************** * really, really simple node class. * Could be expanded with accessor methods, additional data, etc ***********************************************************************/ class Node { public: int value; // value stored in the tree Node * left; // left and right children of the node. 0 if no child. Node * right; Node() { left = right = 0; } // default constructor. pretty trivial }; /*********************************************************************** * Simple-ish binary tree class. * Provides basic insert, remove, empty, and print ***********************************************************************/ class BinaryTree { private: Node * root; // address of first node in the list public: BinaryTree(); // default constructor void insert(int v); // insert v into the tree void empty(); // delete all nodes in the tree void print(); // print contents of tree private: void insert_helper(Node* root, int v); // Helper for the insert method void empty_helper(Node* root); // helper for the empty method void print_helper(Node* root); // print contents of the array }; #endif