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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:53:28+00:00 2026-05-28T18:53:28+00:00

I have a hierarchical data that goes like this: +———————-+——-+ | name | depth

  • 0

I have a hierarchical data that goes like this:

+----------------------+-------+
| name                 | depth |
+----------------------+-------+
| ELECTRONICS          |     0 |
| TELEVISIONS          |     1 |
| TUBE                 |     2 |
| LCD                  |     2 |
| PLASMA               |     2 |
| PORTABLE ELECTRONICS |     1 |
| MP3 PLAYERS          |     2 |
| FLASH                |     3 |
| CD PLAYERS           |     2 |
| 2 WAY RADIOS         |     2 |
+----------------------+-------+

TUBE, LCD and PLASMA are children of TELEVISIONS. FLASH is the child of MP3 PLAYERS. MP3 PLAYERS, CD PLAYERS and 2 WAY RADIOS are the children of PORTABLE ELECTRONICS. You get the drill.

Now, I have a structure Node that contains its Id and its children, and so on, as to build a tree. Like this:

struct Node
{
   int id;
   list<Node*> children;
}

Each item is identified by an ID, which is the row number (ELECTRONICS=0, TELEVISIONS=1, and so on), so it is easy to find out who are the children of a node.

This is the tree I’m trying to build. This tree is not binary, as you can see. So applying recursion doesn’t seem like an easy idea. Correct me if I’m wrong.

So how can I perform this? Help!

  • 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-28T18:53:29+00:00Added an answer on May 28, 2026 at 6:53 pm

    You should use pointers to Nodes instead, otherwise you will be duplicating data in your tree in each level.

    I would also suggest you use an enum instead of int id, it makes the code a bit more clearer.

    there is no problem using recursion with a non-binary tree, you just need to instead of calling left/right (or similar) in your recursive function call each in the list<Node*>.

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

Sidebar

Related Questions

I have this project that displays hierarchical data with huge amounts of text, and
I try to have a treeview that browse potentially cyclic hierarchical data. This means
I have a class that contains hierarchical data. I want to present this data
I have an asp.net backend that creates Hierarchical Data based on IHierarchicalEnumerable. This was
I have some hierarchical data that I need display as a table, can I
I currently have a closure table used for hierarchical data that has 5 million
I have a table containing hierarchical data. There are currently ~8 levels in this
I'm working on a project where I have some hierarchical data that I want
I have a set of hierarchical data that I'm hoping to get into the
In flex 3 I have a hierarchical data structure. I would like to display

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.