Re: [Dev-C++] binary tree search + need to find char*
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Peter M. <pet...@im...> - 2003-07-09 13:42:39
|
Thanks for the book advice, i was looking for a good reference and I
have not yet ventured into STL.
I also feel that the advice about having a balanced tree may be very
appropriate, although the size of the tree should not be problematic at
the moment as there are only a few hundred nodes.
If the binary tree was balanced then code like this should work i hope:
///////////////////////////////////////////////////
DicTreeNode* DicBinaryTree::wordBTreeSearch(DicTreeNode* nodePtr, char*
dicWord ){
if (nodePtr != 0) {
if (strcmp(nodePtr->word,dicWord) < 0) {
this->wordBTreeSearch(nodePtr->leftChild,dicWord);
}
if (strcmp(nodePtr->word,dicWord) > 0) {
this->wordBTreeSearch(nodePtr->rightChild,dicWord);
}
else {
this->rtnNodePtr = nodePtr;
}
return this->rtnNodePtr;
}
else{
return nodePtr = 0;
}
}
////////////////////////////////////////////////////
?
Peter Mead
|