473,322 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Non binary tree implementation in C

3
If somebody has a non binary tree(an example, form shown below) implementation in C, could you pass it along. Sample tree of the form

___________ A___________
| | |
____ M__ __N X
| | | | |
E F G L P

Generic implementation would help.

Thanks
Jul 11 '08 #1
4 10273
Laharl
849 Expert 512MB
You can't really do generics in C, since there's no templates. That said, the easiest way to implement a variable-arity tree is to use two pointers in each node, one to the first child, one to the next sibling.

Expand|Select|Wrap|Line Numbers
  1. struct tree_node {
  2.     int data;
  3.     struct tree_node* first_child; //Points to the first node on the next level down
  4.     struct tree_node* next_sibling; //Points to the next node on the same level
  5. };
  6.  
Jul 11 '08 #2
hurray
3
You can't really do generics in C, since there's no templates. That said, the easiest way to implement a variable-arity tree is to use two pointers in each node, one to the first child, one to the next sibling.

Expand|Select|Wrap|Line Numbers
  1. struct tree_node {
  2.     int data;
  3.     struct tree_node* first_child; //Points to the first node on the next level down
  4.     struct tree_node* next_sibling; //Points to the next node on the same level
  5. };
  6.  

Do you have a C implementation for the kind of tree i pointed.
Jul 11 '08 #3
hurray
3
Do you have a C implementation for the kind of tree i pointed.

A
/ \ \
B C D
/ \
E F

Looks like thre tree had got all messed up. here is a better representation.
Jul 11 '08 #4
Laharl
849 Expert 512MB
You can use that struct as the nodes of the tree by setting the pointer variables within to make that tree. I'm not going to write the code for you, I've given you everything else already.
Jul 11 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: jova | last post by:
Is there a difference between a Binary Tree and a Binary Search Tree? If so can someone please explain. Thank You.
4
by: Max | last post by:
Hi guys, did some searching on the topic, but can't find much more then just basic info on binary trees. I need to write a binary tree implementation so that it is always complete. In other words...
0
by: j | last post by:
Hi, Anyone out there with binary search tree experience. Working on a project due tomorrow and really stuck. We need a function that splits a binary tree into a bigger one and smaller one(for a...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
9
by: GiantCranesInDublin | last post by:
Hi, I am looking for the best performing solution for modifying and iterating an object graph in JavaScript. I have outlined below a simplified example of the object model and examples of how I...
3
by: piotrek | last post by:
Hi I would like to ask you a question. Ian creating app. that download from server directory structure ( whole tree ) and those data are placed in proper places into my treeview control. I...
1
TMS
by: TMS | last post by:
I'm trying to write an address book that is based on a binary tree. I'm devloping in Visual C++ (I blew up my Ubuntu with the new dist, so no EMACS), starting with the basics: #ifndef...
11
by: Defected | last post by:
Hi, How i can create a Binary Search Tree with a class ? thanks
7
by: Vinodh | last post by:
Started reading about Binary Trees and got the following questions in mind. Please help. Definition of a Binary Tree from "Data Structures using C and C++ by Tanenbaum" goes like this, "A...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.