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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:01:32+00:00 2026-06-05T02:01:32+00:00

Please see BST codes below. It only outputs 5. what did I do wrong?

  • 0

Please see BST codes below. It only outputs “5”. what did I do wrong?

#include <iostream>

class bst {
 public:
  bst(const int& numb) : root(new node(numb)) {}

  void insert(const int& numb) {
    root->insert(new node(numb), root);
  }

  void inorder() {
    root->inorder(root);
  }

 private:
  class node {
   public:
    node(const int& numb) : left(NULL), right(NULL) {
      value = numb;
    }

    void insert(node* insertion, node* position) {
      if (position == NULL) position = insertion;
      else if (insertion->value > position->value)
        insert(insertion, position->right);
      else if (insertion->value < position->value)
        insert(insertion, position->left);
    }

    void inorder(node* tree) {
      if (tree == NULL)
        return;
      inorder(tree->left);
      std::cout << tree->value << std::endl;
      inorder(tree->right); 
    }
  private:
    node* left;
    node* right;
    int value;
  };

  node* root;
};

int main() {
  bst tree(5);
  tree.insert(4);
  tree.insert(2);
  tree.insert(10);
  tree.insert(14);
  tree.inorder();
  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-06-05T02:01:34+00:00Added an answer on June 5, 2026 at 2:01 am

    use reference:

    void insert(node* insertion, node* &position)

    void inorder(node* &tree) {

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

Sidebar

Related Questions

Please see the code below: #include <iostream> #include <stdlib.h> #include <time.h> using namespace std;
Please see this piece of code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i
Please see following methods. public static ProductsCollection GetDummyData(int? customerId, int? supplierId) { try {
Please see below code,i getting wrong value. eg; var FirstValue=0.00; var secondvalue=parseFloat(22.88,10).toFixed(2); var thirdvalue=(FirstValue)
Please see below codes and output. NSDateComponents *dateComponents = [[[NSDateComponents alloc] init] autorelease]; [dateComponents
Please see the following code to understand my question better. class compareByValue { public:
Please see below code: thrust::device_vector<int>::iterator whereToBegin = copyListOfNgramCounteachdoc.begin(); end = thrust::unique_by_key(end.first, end.first + numUniqueNgrams,end.second);
Please see the sample xml given below. As per a requirement, I need to
PLEASE SEE THE EDIT BELOW, THE REPORT SEEMS TO USE CACHED DATA? I cant
Please see my current html snippet is as below. I am trying to make

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.