Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8933355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:31:06+00:00 2026-06-15T09:31:06+00:00

I am working on a function that searches a templated binary search tree for

  • 0

I am working on a function that searches a templated binary search tree for a value with a given key and then returns a pointer to that data value. If the given key doesn’t exist in the tree, the pointer it returns should point to NULL. So far I have:

template <typename Item, typename Key>
Item* BSTree<Item,Key>::search(const Key& key) const {
    Item* entry = NULL;
    Node* cursor = root;
    while(cursor != NULL) {
        if(key > cursor->data) 
            cursor = cursor->right;
        else if(key < cursor->data)
            cursor = cursor->left;
        else
            entry = cursor->data;
    }
    return entry;
}

But I get errors when I try and run it that say I can’t convert from Item to Item*. I’ve always had trouble with pointers and can’t figure out a way to fix these errors.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:31:08+00:00Added an answer on June 15, 2026 at 9:31 am

    Instead of entry = cursor->data; you apparently need entry = &(cursor->data);.

    Also note that once you find your item, you probably want to return it immediately, not continue traversing the tree looking at more items.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on creating a binary search algorithm in C that searches for a
I'm working on a search function that finds the song where the search matches
I'm working in PHP and I want to create a function that, given a
I search for the function that run programm by path, and working of main
I am working on a function in WP that searches the post content for
I'm working on a function that is too complicated (processor) so I embedded part
I am working on a function that accepts a JSON object as a parameter.
I'm working on a function that handles events from a number of buttons and
I am working on a function that will essentially see which of two ints
I'm working with a PHP function that takes a string and converts all of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.