text cover

Data Abstraction and Problem Solving with C++

Walls and Mirrors

by Frank M. Carrano

Addison Wesley Logo

BinaryTree Class Reference

#include <BinaryTree.h>

List of all members.


Detailed Description

ADT binary tree.

Definition at line 24 of file BinaryTree.h.

Public Member Functions

 BinaryTree ()
 BinaryTree (const TreeItemType &rootItem) throw (TreeException)
 BinaryTree (const TreeItemType &rootItem, BinaryTree &leftTree, BinaryTree &rightTree) throw (TreeException)
 BinaryTree (const BinaryTree &tree) throw (TreeException)
virtual ~BinaryTree ()
virtual bool isEmpty () const
virtual TreeItemType getRootData () const throw (TreeException)
virtual void setRootData (const TreeItemType &newItem) throw (TreeException)
virtual void attachLeft (const TreeItemType &newItem) throw (TreeException)
virtual void attachRight (const TreeItemType &newItem) throw (TreeException)
virtual void attachLeftSubtree (BinaryTree &leftTree) throw (TreeException)
virtual void attachRightSubtree (BinaryTree &rightTree) throw (TreeException)
virtual void detachLeftSubtree (BinaryTree &leftTree) throw (TreeException)
virtual void detachRightSubtree (BinaryTree &rightTree) throw (TreeException)
virtual BinaryTree getLeftSubtree () const throw (TreeException)
virtual BinaryTree getRightSubtree () const throw (TreeException)
virtual void preorderTraverse (FunctionType visit)
virtual void inorderTraverse (FunctionType visit)
virtual void postorderTraverse (FunctionType visit)
virtual BinaryTreeoperator= (const BinaryTree &rhs) throw (TreeException)

Protected Member Functions

 BinaryTree (TreeNode *nodePtr)
void copyTree (TreeNode *treePtr, TreeNode *&newTreePtr) const throw (TreeException)
void destroyTree (TreeNode *&treePtr)
TreeNoderootPtr () const
void setRootPtr (TreeNode *newRoot)
void getChildPtrs (TreeNode *nodePtr, TreeNode *&leftChildPtr, TreeNode *&rightChildPtr) const
void setChildPtrs (TreeNode *nodePtr, TreeNode *leftChildPtr, TreeNode *rightChildPtr)
void preorder (TreeNode *treePtr, FunctionType visit)
void inorder (TreeNode *treePtr, FunctionType visit)
void postorder (TreeNode *treePtr, FunctionType visit)

Private Attributes

TreeNoderoot


Constructor & Destructor Documentation

BinaryTree::BinaryTree  ) 
 

Definition at line 23 of file BinaryTree.cpp.

Referenced by getLeftSubtree(), and getRightSubtree().

BinaryTree::BinaryTree const TreeItemType rootItem  )  throw (TreeException)
 

Definition at line 27 of file BinaryTree.cpp.

BinaryTree::BinaryTree const TreeItemType rootItem,
BinaryTree leftTree,
BinaryTree rightTree
throw (TreeException)
 

Definition at line 41 of file BinaryTree.cpp.

BinaryTree::BinaryTree const BinaryTree tree  )  throw (TreeException)
 

Definition at line 60 of file BinaryTree.cpp.

BinaryTree::~BinaryTree  )  [virtual]
 

Definition at line 78 of file BinaryTree.cpp.

References destroyTree(), and root.

BinaryTree::BinaryTree TreeNode nodePtr  )  [protected]
 

Definition at line 74 of file BinaryTree.cpp.


Member Function Documentation

bool BinaryTree::isEmpty  )  const [virtual]
 

Definition at line 83 of file BinaryTree.cpp.

References root.

Referenced by getLeftSubtree(), getRightSubtree(), and getRootData().

TreeItemType BinaryTree::getRootData  )  const throw (TreeException) [virtual]
 

Definition at line 88 of file BinaryTree.cpp.

References isEmpty(), TreeNode::item, and root.

void BinaryTree::setRootData const TreeItemType newItem  )  throw (TreeException) [virtual]
 

Definition at line 96 of file BinaryTree.cpp.

Referenced by main().

void BinaryTree::attachLeft const TreeItemType newItem  )  throw (TreeException) [virtual]
 

Definition at line 115 of file BinaryTree.cpp.

Referenced by main().

void BinaryTree::attachRight const TreeItemType newItem  )  throw (TreeException) [virtual]
 

Definition at line 137 of file BinaryTree.cpp.

Referenced by main().

void BinaryTree::attachLeftSubtree BinaryTree leftTree  )  throw (TreeException) [virtual]
 

Definition at line 159 of file BinaryTree.cpp.

void BinaryTree::attachRightSubtree BinaryTree rightTree  )  throw (TreeException) [virtual]
 

Definition at line 173 of file BinaryTree.cpp.

Referenced by main().

void BinaryTree::detachLeftSubtree BinaryTree leftTree  )  throw (TreeException) [virtual]
 

Definition at line 187 of file BinaryTree.cpp.

Referenced by main().

void BinaryTree::detachRightSubtree BinaryTree rightTree  )  throw (TreeException) [virtual]
 

Definition at line 198 of file BinaryTree.cpp.

BinaryTree BinaryTree::getLeftSubtree  )  const throw (TreeException) [virtual]
 

Definition at line 209 of file BinaryTree.cpp.

References BinaryTree(), copyTree(), isEmpty(), TreeNode::leftChildPtr, and root.

Referenced by main().

BinaryTree BinaryTree::getRightSubtree  )  const throw (TreeException) [virtual]
 

Definition at line 222 of file BinaryTree.cpp.

References BinaryTree(), copyTree(), isEmpty(), TreeNode::rightChildPtr, and root.

void BinaryTree::preorderTraverse FunctionType  visit  )  [virtual]
 

Definition at line 235 of file BinaryTree.cpp.

References preorder(), and root.

void BinaryTree::inorderTraverse FunctionType  visit  )  [virtual]
 

Definition at line 240 of file BinaryTree.cpp.

References inorder(), and root.

Referenced by main().

void BinaryTree::postorderTraverse FunctionType  visit  )  [virtual]
 

Definition at line 245 of file BinaryTree.cpp.

References postorder(), and root.

BinaryTree & BinaryTree::operator= const BinaryTree rhs  )  throw (TreeException) [virtual]
 

Definition at line 250 of file BinaryTree.cpp.

void BinaryTree::copyTree TreeNode treePtr,
TreeNode *&  newTreePtr
const throw (TreeException) [protected]
 

Copies the tree rooted at treePtr into a tree rooted at newTreePtr.

Exceptions:
TreeException If a copy of the tree cannot be allocated.

Definition at line 260 of file BinaryTree.cpp.

Referenced by getLeftSubtree(), and getRightSubtree().

void BinaryTree::destroyTree TreeNode *&  treePtr  )  [protected]
 

Deallocates memory for a tree.

Definition at line 283 of file BinaryTree.cpp.

References TreeNode::leftChildPtr, and TreeNode::rightChildPtr.

Referenced by ~BinaryTree().

TreeNode * BinaryTree::rootPtr  )  const [protected]
 

Definition at line 294 of file BinaryTree.cpp.

References root.

void BinaryTree::setRootPtr TreeNode newRoot  )  [protected]
 

Definition at line 299 of file BinaryTree.cpp.

References root.

void BinaryTree::getChildPtrs TreeNode nodePtr,
TreeNode *&  leftChildPtr,
TreeNode *&  rightChildPtr
const [protected]
 

Definition at line 304 of file BinaryTree.cpp.

References TreeNode::leftChildPtr, and TreeNode::rightChildPtr.

void BinaryTree::setChildPtrs TreeNode nodePtr,
TreeNode leftChildPtr,
TreeNode rightChildPtr
[protected]
 

Definition at line 312 of file BinaryTree.cpp.

References TreeNode::leftChildPtr, and TreeNode::rightChildPtr.

void BinaryTree::preorder TreeNode treePtr,
FunctionType  visit
[protected]
 

Definition at line 320 of file BinaryTree.cpp.

References TreeNode::item, TreeNode::leftChildPtr, and TreeNode::rightChildPtr.

Referenced by preorderTraverse().

void BinaryTree::inorder TreeNode treePtr,
FunctionType  visit
[protected]
 

Definition at line 330 of file BinaryTree.cpp.

References TreeNode::item, TreeNode::leftChildPtr, and TreeNode::rightChildPtr.

Referenced by inorderTraverse().

void BinaryTree::postorder TreeNode treePtr,
FunctionType  visit
[protected]
 

Definition at line 340 of file BinaryTree.cpp.

References TreeNode::item, TreeNode::leftChildPtr, and TreeNode::rightChildPtr.

Referenced by postorderTraverse().


Member Data Documentation

TreeNode* BinaryTree::root [private]
 

Pointer to root of tree.

Definition at line 107 of file BinaryTree.h.

Referenced by getLeftSubtree(), getRightSubtree(), getRootData(), inorderTraverse(), isEmpty(), postorderTraverse(), preorderTraverse(), rootPtr(), setRootPtr(), and ~BinaryTree().


The documentation for this class was generated from the following files:

Generated on Sun Aug 27 21:29:17 2006 for AWLogo by  doxygen 1.4.6