//----------------------------------------------------------------------
//  SPECIFICATION FILE (inttree.h)
//  This module is identical to CharTree except IntTree objects
//  are trees of integers, not trees of characters.
//----------------------------------------------------------------------
#include "bool.h"

struct TreeNode;            // Complete declaration hidden in
                            // implementation file
typedef TreeNode* NodePtr;

class IntTree {
public:
    Boolean IsEmpty() const;
        // POST: FCTVAL == (tree has no nodes)

    void BuildRoot( /* in */ int someInt );
        // PRE:  IsEmpty()
        // POST: Tree has root node, call it R
        //    && Contents(R) == someInt  &&  IsLeaf(R)

    NodePtr Root() const;
        // POST: FCTVAL == NULL, if IsEmpty()
        //              == pointer to root node, otherwise

    IntTree();
        // Constructor
        // POST: Created(tree)  &&  IsEmpty()
private:
    NodePtr rootPtr;
};

//......................................................................
// The following operations manipulate nodes indirectly
// through pointers of type NodePtr
//......................................................................

void AppendLeft( /* in */ NodePtr ptr,
                 /* in */ int     someInt );
    // PRE:  ValidNode(*ptr)  &&  Assigned(someInt)
    // POST: New node, call it LC, created as left child of *ptr
    //    && ValidNode(LC)  &&  IsLeaf(LC)  &&  Contents(LC) == someInt
    // NOTE: Dangling pointers may occur if HasLeftChild(*ptr<entry>)

void AppendRight( /* in */ NodePtr ptr,
                  /* in */ int     someInt );
    // PRE:  ValidNode(*ptr)  &&  Assigned(someInt)
    // POST: New node, call it RC, created as right child of *ptr
    //    && ValidNode(RC)  &&  IsLeaf(RC)  &&  Contents(RC) == someInt
    // NOTE: Dangling pointers may occur if HasRightChild(*ptr<entry>)

int Data( /* in */ NodePtr ptr );
    // PRE:  ValidNode(*ptr)  &&  Assigned(Contents(*ptr))
    // POST: FCTVAL == Contents(*ptr)

void Store( /* in */ NodePtr ptr,
            /* in */ int     someInt );
    // PRE:  ValidNode(*ptr)  &&  Assigned(someInt)
    // POST: Contents(*ptr) == someInt

NodePtr LChild( /* in */ NodePtr ptr );
    // PRE:  ValidNode(*ptr)
    // POST: FCTVAL == NULL, if NOT HasLeftChild(*ptr)
    //              == pointer to left child of *ptr, otherwise

NodePtr RChild( /* in */ NodePtr ptr );
    // PRE:  ValidNode(*ptr)
    // POST: FCTVAL == NULL, if NOT HasRightChild(*ptr)
    //              == pointer to right child of *ptr, otherwise

Boolean IsLeaf( /* in */ NodePtr ptr );
    // PRE:  ValidNode(*ptr)
    // POST: FCTVAL == IsLeaf(*ptr)

void DeleteLeaf( /* inout */ NodePtr& ptr );
    // PRE:  IsLeaf(*ptr<entry>)
    // POST: *ptr<entry> removed from tree  &&  ptr is undefined



