Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Recursive binary search tree

Posted on 2007-11-27
9
Medium Priority
?
765 Views
Last Modified: 2010-04-21
I'm trying to call my function for RetrieveItem from the test driver I'm creating.  I keep getting errors though when I compile.  I have to test to see if the item is there and say yes or no.  I've spent an hour trying different combinations to call the function and I keep coming up empty.  Any ideas?  Here is the snippet of the MAIN that I'm trying to write and then the recursive functions I've written to complete my goal.

 case 'R': //Retrieve an item from the tree
                {
                    if (status = t1.RetrieveItem(item))
                     cout << item <<  " was found in the tree. " << endl << endl;
                    else
                    cout << item << " was not found in the tree. " << endl << endl;
                }
                break;



 template <class ItemType>
void RTreeType<ItemType>::RetrieveItem(ItemType& item, bool& found) // retrieve an item
{
    Retrieve(root, item, found);



template <class ItemType>
void RTreeType<ItemType>::Retrieve(NodeType* tree, ItemType& item, bool& found)
{
    if (tree == NULL)
        found = false;
    else if (item < tree->info)
        Retrieve(tree->left, item, found);
    else if (item > tree->info)
        Retrieve (tree->right, item, found);
    else
    {
        item = tree->info;
        found = true;
    }
}
0
Comment
Question by:PMG76
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 20360402
So, what exactly is the problem when you try and compile?
0
 

Author Comment

by:PMG76
ID: 20360417
prog7a.cpp: In function `int main()':
prog7a.cpp:101: error: no matching function for call to `RTreeType<int>::RetrieveItem(int&)'
0
 

Author Comment

by:PMG76
ID: 20360419
RTreeType.h:158: note: candidates are: void RTreeType<ItemType>::RetrieveItem(ItemType&, bool&) [with ItemType = int]
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 40

Expert Comment

by:evilrix
ID: 20360439
t1.RetrieveItem(item)

RetrieveItem(ItemType& item, bool& found)

The definition requires a bool passed as the 2nd param.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20360447
Try: -
case 'R': //Retrieve an item from the tree
                {
                    bool found;
                    if (status = t1.RetrieveItem(item, &found))
                     cout << item <<  " was found in the tree. " << endl << endl;
                    else
                    cout << item << " was not found in the tree. " << endl << endl;
                }
                break;

Open in new window

0
 
LVL 20

Accepted Solution

by:
ikework earned 1000 total points
ID: 20360463
if (status = t1.RetrieveItem(item))

RetrieveItem returns nothing, it was declared to return void:

void RTreeType<ItemType>::Retrieve(NodeType* tree, ItemType& item, bool& found)

so "status = " does not work. i guess you mean

  t1.RetrieveItem(item,status)
  if( status )
    cout << item <<  " was found in the tree. " << endl << endl;
  else
    cout << item << " was not found in the tree. " << endl << endl;


ike
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 1000 total points
ID: 20360466
>> The definition requires a bool passed as the 2nd param.

And it doesn't return anything, so you can't assign the return value to status. You probably want to clal it like this :


       case 'R': //Retrieve an item from the tree
                {
                    t1.RetrieveItem(item, status)
                    if (status)
                     cout << item <<  " was found in the tree. " << endl << endl;
                    else
                    cout << item << " was not found in the tree. " << endl << endl;
                }
                break;
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20360484
Well observed, I was just reaching that conclusion myself :)
0
 

Author Closing Comment

by:PMG76
ID: 31411271
I knew it was something silly.  After 6 hours my mind has melted I think.  Thanks guys!
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question