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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:13:35+00:00 2026-05-27T11:13:35+00:00

I am having problems when I am attempting to : (1) find the largest

  • 0

I am having problems when I am attempting to :
(1) find the largest info field in the left sub-tree of the root of the original tree
(2) find the smallest info field in the right sub-tree of the root of the original tree.

My code compiles but then it has errors when it executes and I’m unclear of what is happening in my maxleftsubtree() and minrightsubtree() functions. Any suggestions would be appreciated.

My current code:

#include <iostream>
#include <string>

using namespace std;

class Tnode {
    public:
        Tnode *left;
        string info;
        Tnode *right;
        Tnode(string info = "", Tnode* left = NULL, Tnode* right = NULL) :
            info(info), left(left), right(right) {}
};
class BST {
    public:
        BST() : theroot(NULL) {}
        void insert(string x);
        void inorderprint();
        void preorderprint();
        void postorderprint();
        void maxstring();
        void minstring();
        void maxleftsubtree();
        void minrightsubtree();
    private:
        void inorderprint(Tnode *p);
        void preorderprint(Tnode *p);
        void postorderprint(Tnode *p);
        void maxstring(Tnode *p);
        void minstring(Tnode *p);
        void maxleftsubtree(Tnode *p);
        void minrightsubtree(Tnode *p);
        void insertleft(Tnode *place, string newval);
        void insertright(Tnode *place, string newval);
        Tnode *theroot;
};

// add a new node (with x as info) to tree that has theroot as root
void BST::insert(string x)
{
    // if the tree is initially empty, put x at the root
    if (theroot==NULL) {
        theroot = new Tnode(x);
        return;
    }

    Tnode *p, *q;

    // otherwise, find where x belongs in the tree
    p = theroot;
    q = theroot;
    while ( q != NULL) {
        p = q;
        if (x < p-> info)
            q = p-> left;
        else
            q = p-> right;
    }

    // to get here, we found the correct place to store x,
    // as a child of node p        Q: is it left or right?

    if (x < p-> info)
        insertleft(p,x);
    else
        insertright(p,x);

    return;

}

//insert a new node (with info newval) as left child of place
void BST::insertleft(Tnode *place, string newval)
{
    Tnode *p = new Tnode(newval);

    place -> left = p;
    return;

}

//insert a new node (with info newval) as right child of place
void BST::insertright(Tnode *place, string newval)
{
    Tnode *p = new Tnode(newval);

    place -> right = p;
    return;

}
......................
...............
...............

//
//
void BST::maxleftsubtree()
{
    maxleftsubtree(theroot);
}

//
//
void BST::minrightsubtree()
{
    minrightsubtree(theroot);
}

.....................................
.................................
.........................

//
//
void BST::maxleftsubtree(Tnode *p)
{
    while (p -> left)
        p = p -> right;
    cout << p -> info << " \n";
    return;
}

//
//
void BST::minrightsubtree(Tnode *p)
{
    while (p -> right)
        p = p -> left;
    cout << p -> info << " \n";
    return;
}
  • 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-27T11:13:36+00:00Added an answer on May 27, 2026 at 11:13 am

    There is an error in your maxleftsubtree(maxtrightsubtree) function. You should first select the left(right) subtree of the root, the walk along the right(left) branch to the end. Here is a modified version:

    void BST::maxleftsubtree(Tnode *p)
    {
        Tnode* left = NULL;
        if (p != NULL) {
            left = p->left;
        }
        if (left != NULL) {
            while (left->right) 
                left = left -> right;
            cout << left -> info << " \n";
        }
        return;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently having problems with attempting to style the HTML rich text editor
I'm having some problems attempting to create a multi-threaded Server. Everything works fine until
I'm attempting to populate a drop down from an Nhibernate object, but having problems
I'm having some problems while attempting to serialize a libxml2 object in python. In
I'm having a problem with a simple form where i'm attempting to fire an
Having problems with a small awk script, Im trying to choose the newest of
Having problems iterating. Problem has to do with const correctness, I think. I assume
Im having problems displaying records to my view when passing viewdata to a user
Im having problems building a query with the linq to sql data query expression
Im having problems with classpaths. I have used them before with import but I'm

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.