need help-
create a tree(simple m-ary),with each node having 4 dataitems & 5 children. "IN C-language"

just 1 example showing 1 or 2 node created will be really helpfull(as this is tedious)........i have all operation clear till binary tree...but this 1 is not clicking!!!!.....

or in case u knw any link with ready-made Code...then the link.

Anything,any help is welcomed..
Thanks in advance.

Recommended Answers

All 6 Replies

Do you know how to create a binary tree ? It is the same principle, but instead of 2 children now you have 5 children.

Also does the problem state any restrictions on how you have to insert the node ? In the sense does the tree have to be balanced or you can insert the node where ever you want ?

its not balanced..........

So you can insert the node in which ever branch you chose to ?
PS: the level of help that you receive here often depends on how much detail you can provide

Node-1 with 5 chidren nodes node2 node3 node4 node5 node6...........

Node-1 contains 4 dataitems(integers)

the child node(node-2) to the left of dataitem-1 contains max. 4 values-all less than dataitem-1 of node-1
the child node(node-3) to the right of dataitem-1 contains max. 4 values-all greater than dataitem-1 of node-1 & less than dataitem-2 of node-1

the child node(node-4) to the right of dataitem-2 contains max. 4 values-all greater than dataitem-2 of node-1 & less than dataitem-3 of node-1 ................

Following this criteria we are supposed to insert integer values in the tree....

No condition like each node must be at-least half full as this isn't like binary tree

The data structure of each node will be some thing of this sort

struct node
{
     int data[5];
     struct node* children[5];
     int count;
};

Create the head node first. The when you insert the next node, check how many children does head have. If it has less than 5 children, make the next node the child of the head. If not check how many children does the first child have then check for the 2nd child and so on
This approach is not complete but you can build on this now

Be a part of the DaniWeb community

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