Click here to Skip to main content
15,884,629 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Menu in dialog application, CheckMenuItem [modified] Pin
mla15426-Mar-10 7:07
mla15426-Mar-10 7:07 
AnswerRe: Menu in dialog application, CheckMenuItem Pin
mla15426-Mar-10 7:17
mla15426-Mar-10 7:17 
Questionuse custom icon on an AfxMessageBox Pin
b-rad31126-Mar-10 6:29
b-rad31126-Mar-10 6:29 
AnswerRe: use custom icon on an AfxMessageBox PinPopular
jeron126-Mar-10 7:03
jeron126-Mar-10 7:03 
GeneralRe: use custom icon on an AfxMessageBox Pin
b-rad31126-Mar-10 8:18
b-rad31126-Mar-10 8:18 
QuestionHelp with binary tree(BST) function building. Pin
Member 382253226-Mar-10 4:52
Member 382253226-Mar-10 4:52 
AnswerRe: Help with binary tree(BST) function building. Pin
David Crow26-Mar-10 5:28
David Crow26-Mar-10 5:28 
GeneralRe: Help with binary tree(BST) function building. Pin
Member 382253226-Mar-10 6:45
Member 382253226-Mar-10 6:45 
Thanks for your quick response.
Unfortunately, I don't think that your solution works with mine.
I tried implementing it, but the your node(in your code) behaves differently from mine.
Mine is actually called a TreeNode, and its members are private, so I can't access them.

Here, I'm going to post all of the code:

IN BST.H:

/** @file BST.h */
#include "TreeException.h"
#include "TreeNode.h"

typedef void (*FunctionType)(TreeItemType& anItem);


class BinarySearchTree
{
public:
// constructors and destructor:
   BinarySearchTree();
   BinarySearchTree(const BinarySearchTree& tree)
      throw(TreeException);
   virtual ~BinarySearchTree();


   virtual bool isEmpty() const;


   virtual void searchTreeInsert(const TreeItemType& newItem)
      throw(TreeException);

  
   virtual void searchTreeDelete(KeyType searchKey)
      throw(TreeException);

 
   virtual void searchTreeRetrieve(KeyType searchKey,
				   TreeItemType& treeItem) const
      throw(TreeException);

   virtual void preorderTraverse(FunctionType visit);


   virtual void inorderTraverse(FunctionType visit);

  
   virtual void postorderTraverse(FunctionType visit);

// overloaded operator:
   virtual BinarySearchTree& operator=(const BinarySearchTree& rhs)
      throw(TreeException);

protected:

   void insertItem(TreeNode *& treePtr,
                   const TreeItemType& newItem)
      throw(TreeException);

   void deleteItem(TreeNode *& treePtr, KeyType searchKey)
      throw(TreeException);


   void deleteNodeItem(TreeNode *& nodePtr);

   
   void processLeftmost(TreeNode *& nodePtr,
                        TreeItemType& treeItem);


   void retrieveItem(TreeNode *treePtr, KeyType searchKey,
                     TreeItemType& treeItem) const
      throw(TreeException);


   void copyTree(TreeNode *treePtr, TreeNode *& newTreePtr) const
      throw(TreeException);
   void destroyTree(TreeNode *& treePtr);

   void preorder(TreeNode *treePtr, FunctionType visit);
   void inorder(TreeNode *treePtr, FunctionType visit);
   void postorder(TreeNode *treePtr, FunctionType visit);

   TreeNode *rootPtr() const;
   void setRootPtr(TreeNode *newRoot);

   void getChildPtrs(TreeNode *nodePtr,
                     TreeNode *& leftChildPtr,
                     TreeNode *& rightChildPtr) const;
   void setChildPtrs(TreeNode *nodePtr,
                     TreeNode *leftChildPtr,
                     TreeNode *rightChildPtr);

private:
   /** Pointer to root of tree. */
   TreeNode *root;
}; // end BinarySearchTree
// End of header file.


in TreeNode.h:
/** @file TreeNode.h */
//TreeNode559.h
#include "KeyedItem.h"

typedef KeyedItem TreeItemType;


class TreeNode
{
private:
   TreeNode() {}
   TreeNode(const TreeItemType& nodeItem,
            TreeNode *left = NULL, TreeNode *right = NULL)
      : item(nodeItem), leftChildPtr(left),
      rightChildPtr(right) {}

   
   TreeItemType item;
   
   TreeNode *leftChildPtr, *rightChildPtr;

   // friend class - can access private parts
   friend class BinarySearchTree;
}; // end TreeNode

in keyeditem.h
/** @file KeyedItem.h */
//KeyedItem559.h

typedef int KeyType;


class KeyedItem
{
public:
   KeyedItem() {}
   KeyedItem(const KeyType& keyValue)
      : searchKey(keyValue) {}
   KeyType getKey() const
   {  return searchKey;
   }  // end getKey
private:
   KeyType searchKey;
}; // end KeyedItem


Thanks again for the quick response.
GeneralRe: Help with binary tree(BST) function building. Pin
David Crow26-Mar-10 7:35
David Crow26-Mar-10 7:35 
AnswerRe: Help with binary tree(BST) function building. Pin
Member 382253226-Mar-10 8:03
Member 382253226-Mar-10 8:03 
GeneralRe: Help with binary tree(BST) function building. Pin
Member 382253226-Mar-10 8:09
Member 382253226-Mar-10 8:09 
GeneralRe: Help with binary tree(BST) function building. Pin
David Crow26-Mar-10 8:11
David Crow26-Mar-10 8:11 
GeneralRe: Help with binary tree(BST) function building. Pin
Member 382253226-Mar-10 8:24
Member 382253226-Mar-10 8:24 
QuestionRe: Help with binary tree(BST) function building. Pin
David Crow26-Mar-10 8:36
David Crow26-Mar-10 8:36 
AnswerRe: Help with binary tree(BST) function building. Pin
Member 382253226-Mar-10 8:55
Member 382253226-Mar-10 8:55 
AnswerRe: Help with binary tree(BST) function building. Pin
David Crow26-Mar-10 8:58
David Crow26-Mar-10 8:58 
GeneralRe: Help with binary tree(BST) function building. Pin
Member 382253226-Mar-10 9:15
Member 382253226-Mar-10 9:15 
GeneralRe: Help with binary tree(BST) function building. Pin
David Crow26-Mar-10 9:29
David Crow26-Mar-10 9:29 
GeneralRe: Help with binary tree(BST) function building. Pin
Member 382253226-Mar-10 9:34
Member 382253226-Mar-10 9:34 
GeneralRe: Help with binary tree(BST) function building. Pin
David Crow26-Mar-10 9:36
David Crow26-Mar-10 9:36 
GeneralRe: Help with binary tree(BST) function building. Pin
Member 382253226-Mar-10 9:44
Member 382253226-Mar-10 9:44 
Questionfatal error c1083 in C# Pin
sindhumahe26-Mar-10 4:13
sindhumahe26-Mar-10 4:13 
AnswerRe: fatal error c1083 in C# Pin
Chris Losinger26-Mar-10 4:17
professionalChris Losinger26-Mar-10 4:17 
QuestionButton Caption Pin
shiv@nand26-Mar-10 3:13
shiv@nand26-Mar-10 3:13 
AnswerRe: Button Caption Pin
CPallini26-Mar-10 3:21
mveCPallini26-Mar-10 3:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.