Re: Binary Search Tree input question
From: Alexander Magidow (amagidow_at_DELETEPERIOD2.wisc.edu)
Date: 07/27/04
- Next message: Yusuf B Gursey: "Re: viol."
- Previous message: Keith Edgerley: "Re: Foxes, bibles"
- In reply to: Henry Jordon: "Binary Search Tree input question"
- Next in thread: Sericinus hunter: "Re: Binary Search Tree input question"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 27 Jul 2004 10:53:27 -0500
Henry Jordon wrote:
> I have everything pretty much done but I need to fix something in my
> coding. I want to be able to enter strings such as "love", "hate",
> "the", etc. but am unable to figure how to do this. I have put my .cpp
> and my .h code below. Please help and thank you very much.
>
>
>
> // Recursively insert an item in the tree, if not already present.
> // Note that we pass root by reference.
> void BinarySearchTree::Insert( DataType item, TreeNode* & root )
> {
> if ( root == NULL ) // hit NULL pointer, insert here
> {
> root = new TreeNode( item );
> if ( root == NULL )
> cerr << "Error: cannot allocate memory for TreeNode in
> Insert()!\n";
> }
>
So have you overloaded < or > for "item" so that it makes sense for
strings? I mean, if you have random numbers, that should work - those
operators are straightforward for that type. As for strings(I don't
really know that much about more modern C++, sorry. And this whole thing
gives me bad flashbacks to my algorithms class <shudder> ) it seems like
this is nonsensical - probably compares memory addresses or something.
But I could be wrong. This is also, probably, NOT the right newsgroup to
ask this question of.
> else if ( item < root->data ) // insert in left subtree
> Insert( item, root->left );
>
> else if ( item > root->data ) // insert in right subtree
> Insert( item, root->right );
> }
>
> // Recursive inorder tree traversal (called by Print function).
> // Print the tree on its side, rotated counterclockwise to show
> structure.
>
> again thanks for the help
- Next message: Yusuf B Gursey: "Re: viol."
- Previous message: Keith Edgerley: "Re: Foxes, bibles"
- In reply to: Henry Jordon: "Binary Search Tree input question"
- Next in thread: Sericinus hunter: "Re: Binary Search Tree input question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|