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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:52:16+00:00 2026-06-14T02:52:16+00:00

My instructor has a specific output requirement for the way that the Binary Tree

  • 0

My instructor has a specific output requirement for the way that the Binary Tree should be printed.
He wants the output to be like so:

root { left_subtree }-{ right_subtree }

i.e:

12 {18} –{24}

18 {6} –{14}

6 {NULL} –{NULL}

etc…

I did not realize this till today, and I was already excited that I got my program to work.

template<class elemType>
struct nodeType
{
    elemType info;
    nodeType<elemType> *lLink;
    nodeType<elemType> *rLink;
};

template<class elemType>
void bSearchTreeType<elemType>::printPreOrder(nodeType<elemType> *root1)
{
    if(root1 != NULL) {
        cout<<root1->info<<" "<<"{"<<root1->lLink<<"}"<<endl;//this is where I get the errors 
        printPreOrder(root1->lLink);
        printPreOrder(root1->rlink);
    }
}

template <class elemType>void bSearchTreeType<elemType>::insert(const elemType&  insertItem){

    nodeType<elemType> *current; //pointer to traverse the tree
    nodeType<elemType> *trailCurrent; //pointer behind current
    nodeType<elemType> *newNode;  //pointer to create the node

    newNode = new nodeType<elemType>;    newNode->info = insertItem;
    newNode->lLink = NULL;
    newNode->rLink = NULL;


    if (root1 == NULL)
        root1 = newNode;
    else {   
        current = root1;
        while (current != NULL)
        {
            trailCurrent = current;
            if (current->info == insertItem)
            {
                cout << "The item to be inserted is already "; 
                cout << "in the tree -- duplicates are not allowed." << endl;
                return;        
            }
            else if (current->info > insertItem)
                current = current->lLink;
            else
                current = current->rLink;
        }//end while

        if (trailCurrent->info >insertItem)
            trailCurrent->lLink = newNode;       
        else
            trailCurrent->rLink = newNode;    
    }
}

How would I get my function to print out the left subTree and the right subTree. Everytime I try something I get a segmentation fault or weird memory address are output.

I am looking for guidance and help, anything from pseudo code to how to do it would be awesome. I am just confused

EDITED: To include the insert function and what I do when I get the 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-14T02:52:17+00:00Added an answer on June 14, 2026 at 2:52 am

    You may try something along these lines:

    template<class elemType>
    void bSearchTreeType<elemType>::printPreOrder(nodeType<elemType> *root) {
       if( root ) { 
            cout << root->info << " " << endl;
    
            cout << "{";
            if( root->left ) {
                cout << root->left->info;
            }
            else {
                cout << "NULL";
            }
            cout << "} -- ";
    
            cout << "{";
            if( root->right ) {
                cout << root->right->info;
            }
            else {
                cout << "NULL";
            }
            cout << "}";
    
            cout << endl;
    
            printPreOrder( root->left );
    
            printPreOrder( root->right );
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning by way of tutorials, and the instructor used a validation routine that
I understand that each CPU/architecture has it's own instruction set, therefore a program(binary) written
When an assembly has an instruction like jmp f what happens to the stack
I have such tables in my database like Customer , Member , Instructor ,
I would like to find out if anyone has existing work surrounding formatting an
I have to implement an API for a homework assignment, and my instructor has
psycopg2's doc has an instruction on how to cast a specific type to a
I have a RadGrid which on RowClick should send a specific value to the
I'm taking a java class and the instructor has had us build a HashMap
I am the lead instructor of web & internet related courses on a private

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.