Code Fragment: LinkedBinaryTree1



template <typename Object>
class LinkedBinaryTree {
protected:
  // ... (insert Node definition here)
public:
  // ... (insert Position definition here)
private: 						// member data
  NodePtr    theRoot;					// pointer to the root
  int        sz;					// number of nodes
protected: 						// protected utilities
  // ... (insert LinkedBinaryTree utilities here)
public:
  LinkedBinaryTree()					// constructor
    { theRoot = new Node; sz = 1; }
  int size() const  					// size of tree
    { return sz; }
  bool isEmpty() const 					// is tree empty?
    { return (sz == 0); }
  Position root() const 				// returns root
    { return Position(theRoot); }
  Position leftChild(const Position& v) const 		// returns left child
    { return Position(nodePtr(v)->left); }
  // ... (rightChild(), parent(), and sibling() are omitted but similar)
  bool isRoot(const Position& v) const 			// is v the root?
    { return isRoot(nodePtr(v)); }
  bool isInternal(const Position& v) const 		// is v internal?
    { return isInternal(nodePtr(v)); }
  bool isExternal(const Position& v) const 		// is v external?
    { return isExternal(nodePtr(v)); }
  void replaceElement(const Position& v, const Object& o)
    { replaceElement(nodePtr(v), o); }			// replace element
  void swapElements(const Position& v, const Position& w)
    { swapElements(nodePtr(v), nodePtr(w)); }		// swap elements
  void expandExternal(const Position& v)
    { expandExternal(nodePtr(v)); }			// expand external node
  Position removeAboveExternal(const Position& v)	// remove v and parent
    { return Position(removeAboveExternal(nodePtr(v))); }
  // ... (housekeeping and iterator functions omitted)
};