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 6066639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:31:20+00:00 2026-05-23T09:31:20+00:00

Can someone tell me what the following lines do else if ( obj <

  • 0

Can someone tell me what the following lines do

else if ( obj < retrieve() ) 
{
    return ( left() == 0 ) ? 0 : left()->erase( obj, left_tree );
} 
else 
{
    return ( right() == 0 ) ? 0 : right()->erase( obj, right_tree );
}

in the code block below:

    template <typename Comp>
    int Binary_search_node<Comp>::erase( Comp const &obj, Binary_search_node<Comp> *&ptr_to_this) 
{
    if ( obj == retrieve() ) {
        if ( leaf() ) { // leaf node
            ptr_to_this= 0;
            delete this;
        } 
        else if ( left() != 0 && right() != 0 ) { // full node
            element= right()->front();
            right()->erase( retrieve(), right_tree );
        } 
        else { // only one child
            ptr_to_this= ( left() != 0 ) ? left() : right();
            delete this;
        }
        return 1;
    } 
    else if ( obj < retrieve() ) {
        return ( left() == 0 ) ? 0 : left()->erase( obj, left_tree );} 
    else {
        return ( right() == 0 ) ? 0 : right()->erase( obj, right_tree );}
}

Extra Information:

1)

front() -- finds the minimum objects

Implementation:

template <typename Comp>
Comp Binary_search_node<Comp>::front() const 
{
    return( left() == 0 ) ?retrieve() :left()->front();
}

2)

left()  -- returns pointer to left subtree

3)

right() -- returns pointer to right subtree

4)

*ptr_to_this points to current object (same location as what *this points to)


I have an idea of what the lines do, but I am not 100% sure thus I wanted to confirm. Please note that this erase() function is for a binary search tree. Thanks!

  • 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-05-23T09:31:21+00:00Added an answer on May 23, 2026 at 9:31 am

    erase appears to be implemented recursively. At each stage, we test whether the object to erase is equal to the current object, or whether we need to go down into the left or right child.

    If the child that we want to go into does not exist (left() == 0 or right() == 0), then we cannot erase the object (because it’s not in the tree), so we return 0. Otherwise, we recurse into the child function, and return whatever it returns.

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

Sidebar

Related Questions

Can someone please tell me how I can implement the following line of pseudo-code.
can someone tell me why the following behavior occurs (Oracle 10.2): SQL> create table
Can someone tell me please why the following example work in Firefox but not
Can someone tell me how I can make the following output? I have a
Can someone tell me what the code equivelant in VB.Net to this C# code
Can someone tell me what exactly the two above lines of javascript do? And
Can someone tell me why the commented line of code (one before last) does
In the above scenario I am getting the following compile error. Can someone tell
Can someone tell me if the following function declaration is the correct way to
Can someone tell me how i can change the .xml file that a flash

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.