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.....

plz help,Thanks in advance......

Comments
Sharpen your communication skills.

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.

Edited 6 Years Ago by Narue: n/a

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.

Edited 6 Years Ago by Tellalca: n/a

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;
    struct node *link[M];
};

Edited 6 Years Ago by Narue: n/a

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.

This article has been dead for over six months. Start a new discussion instead.