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

  • Home
  • SEARCH
  • 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 6841443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:58:02+00:00 2026-05-26T23:58:02+00:00

I am doing a a question in the book that asks me to write

  • 0

I am doing a a question in the book that asks me to write constructor and copy-control members for a class that has following variables. Can someone gimme a scenario/example where this class is useful? possible some codes in main function? The part I got confused is that why it needs TreeNode* left and TreeNode* right. I cannot think of the use of them.

#include <iostream>
#include <string>
using namespace std;
class TreeNode
{
public:
    //constructor
    TreeNode(const string& s, const int& n, const TreeNode& lm, const TreeNode& rm):
        value(s), count(n), left(new TreeNode(lm)), right(new TreeNode(rm)) {}
    //copy-constructor
    TreeNode(const TreeNode& m): value(m.value), count(m.count), left(new TreeNode(*m.left)), right(new TreeNode(*m.right)) {}
    //assignment operator
    TreeNode& operator=(const TreeNode& m)
    {
        value = m.value;
        count = m.count;
        *left = *m.left;
        *right = *m.right;
        return *this;   
    }
    //destructor
    ~TreeNode()
        {
      delete left;
      delete right;
    }
private:
    string value;
    int count;
    TreeNode *left;
    TreeNode *right;
};
int main ()
{
    return 0;
}
  • 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-26T23:58:03+00:00Added an answer on May 26, 2026 at 11:58 pm

    You could use this class to store elements from a binary tree (see http://en.wikipedia.org/wiki/Binary_tree) in which case the left and right members probably make sense.

    Binary trees are for instance used for storing data in an ordered way. While inserting elements is potentially costly, looking up an element is pretty fast with a complexity of O(log n).

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

Sidebar

Related Questions

The book I'm currently reading has me write the following code : -(IBAction)displaySomeText:(id)sender {
Whilst doing exam revision I am having trouble answering the following question from the
I have a quite stupid question. How can I make sure that my XML
As I'm learning the iPhone API, the book I'm using has me doing everything
I'm reading an Objective-C book and I have a question that the book doesn't
I am doing a book exercise regarding the Ackermann function. I have one question
I am doing project euler question 33 and have divised a refactor to solve
After taking a look at this SO question and doing my own research, it
Here is the updated question: the current query is doing something like: $sql1 =
Simple question, hopefully an easy way and just want to verify I'm doing it

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.