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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:42:15+00:00 2026-06-08T15:42:15+00:00

a / \ a a / \ / \ a c a f /

  • 0
          a
        /    \ 
       a       a
      / \     /  \
     a   c    a   f 
    / \      / \ 
   b   d    e   g

I have a tree that looks like the above, represented by a linked structure:

   class Node
    {
       Node* leftChild; 
       Node* rightChild; 
       char data;
    }

class Tree
{
   Node* root;
}

My goal is to find all the paths from the root to leaf nodes.

My tree traversal algorithm looks like this:

 void inorder()
  {
    in(root);
  }

  void in(CharNode* currentNode)
  {
    if(currentNode)
      {   
        in(currentNode->leftChild);
        cout << currentNode->data << endl;
        in(currentNode->rightChild);
      }   
  }

When I run this, I am positive that the tree is being built as shown. I have tested that. I cannot, however, figure out why my tree traversal segmentation faults.

The output I get is :

b

Segmentation fault.

I have tested it on trees with smaller heights, and it works. But for some reason it doesn’t work on a trees with heights larger than 2. I thought it was something going wrong with the tree, I have gone through and printed each parent, left child, and right child and they print out as shown. So it’s definitely the traversal algorithm.

  • 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-08T15:42:17+00:00Added an answer on June 8, 2026 at 3:42 pm

    As you build your tree, be sure to initialize leftChild and rightChild to NULL (0) on your nodes. This is critical for leaf-nodes and for nodes missing either a leftChild or a rightChild.

    class Node
          : leftChild(0)
          , rightChild(0)
          , data(0)
    {
       Node* leftChild; 
       Node* rightChild; 
       char data;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have a tree display custom data that looks like this.
In C# I have an intrusive tree structure that looks like this: public abstract
I have a data-structure (in plist) that looks something like this: What i have
I have a binary tree in unordered list that looks like this: <ul> <li>1
I have a binary tree class that is created with a root node and
I have a class structure which looks like: class TestResults { public bool IsSuccess;
I have a database that looks like this: I can generate a tree from
I have a tree that looks like the following B / \ A D
I have an object tree that looks something like Ball / \ LegalBall IllegalBall
I have a file with data that looks like that : ID attribute 1

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.