C-implementation of M-ary/multiway tree......
madam has asked me to do it as part of my project....
node will contain simple integer numbers....

i didn't code any code for it in book/internet.....

0x69 commented: Sharpen your communication skills. +0

## All 8 Replies

What do you want?

implentation of m-ary tree in C.........-any simple example?

implentation of m-ary tree in C

If you understand the concept then an implementation isn't terribly difficult with a little effort on your part. So go do your own homework. We won't bail you out. kthxbye.

any simple example?

No. In my experience, people asking for "simple" examples of something reasonably complex don't understand the simplest example possible and then continue to ask for explanations and excessive hand holding. It's a waste of time to type up the example in the first place, so I don't do it anymore unless you show promise.

``````struct node
{
int data;
node *child1;
node *child2;
.
.
node *childm;
}``````

This is a very basic example. Then you must implement the addNode, traverseTree, searchTree
and other functions to use the structure. When implementing a tree you will need a lot of recursion or stack in order to traverse, search and to use other features that tree offers.

``````node *child1;
node *child2;
.
.
node *childm;``````

Even the most basic of basic examples will use an array to store links. Once you get beyond two links (even there an array is helpful), it becomes exponentially more tedious to work with nodes. Just an FYI.

``````struct node
{
int data;
};``````

Narue is right of course. I gave the example so that he can see the exact situation.

Since I generally use binary trees it is a habit for me to declare the pointers seperately.

Since I generally use binary trees it is a habit for me to declare the pointers seperately.

I did that for a while before realizing that it's cleaner to use an array even for binary trees. Instead of manually writing two symmetric cases for the left and right link, you can roll that up into one case and use a simple calculation to determine which index you want. I've found this to be absolutely invaluable when the symmetric cases start getting larger, such as with balanced binary search trees.

That is a good info. I will try it and see if it fits me better.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.