Re: Binary Search Tree input question

From: Alexander Magidow (amagidow_at_DELETEPERIOD2.wisc.edu)
Date: 07/27/04


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



Relevant Pages

  • Re: Problems opening files not stored in My Documents.
    ... Microsoft's Legal Users' Guide) http://addbalance.com/usersguide ... This message is posted to a newsgroup. ... Took it and downloaded your fix. ... You may experience problems in Windows Explorer or in the Windows ...
    (microsoft.public.word.application.errors)
  • Re: IE 6.0 problems
    ... > fix it so someone please help me out. ... Winsock Fix Utility ... Download Sysclean.com, from Trend Micro, here: ... Please reply to the newsgroup so others may benefit. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Suggestions for ridding myself of some malware
    ... If something happens that you don't like and can't fix, you can always uninstall, clean the -registry and re-install.The problem will be gone. ... Your browser cannot be hi-jacked or abused as easily at all with these browsers. ... This may not be such a good thing: Any real email address found on newsgroup is automatically collected by spam email harvesters. ...
    (alt.comp.hardware.pc-homebuilt)
  • Re: Defect in Security Update KB942615 for Internet Explorer 6
    ... don't think to check for a more appropriate newsgroup for my question. ... Does anyone know if MS is planning on an update to fix like next Tuesday? ... However, when it comes to getting an update to download and install, there ... I always reboot whether or not the offer is there - a few months ago MS ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: AutoComplete in Word
    ... AutoText entry of the Date or CreateDate field and give it a unique name at ... please post all follow-ups to the newsgroup so ... Perhaps the only fix is to try reinstalling Word? ... >> Microsoft MVP ...
    (microsoft.public.word.docmanagement)

Quantcast