I'm trying to build a simple m-way search tree (no need to balance, m is given), does the following function look correct? How can i move to next child node if the curent is full?
===================================================
typedef struct TreeNode {
int num_of_keys;
int *keys;
struct TreeNode **children;
} TREENODE;
/* Insert(...) inserts key into the N-way search tree pointed to by root. It returns NULL if key already exists*/
struct TreeNode* Insert(struct TreeNode *root, int key)
{
if ( root == NULL )
{
root = (TreeNode **)malloc(sizeof(TreeNode *) * num_of_keys);
root->keys[0] = key;
root->num_of_keys = root->num_of_keys - 1;
}
else
{
for ( s=0; (s<root->num_of_keys); s++ );
{
if ( key == root->keys )
return NULL;
else
{
if (key<root->keys)
keys[s+1] = keys; /***shift****/
else{
key[s+1] = key;
s = s+1;
}
}
}
}
}
===================================================
typedef struct TreeNode {
int num_of_keys;
int *keys;
struct TreeNode **children;
} TREENODE;
/* Insert(...) inserts key into the N-way search tree pointed to by root. It returns NULL if key already exists*/
struct TreeNode* Insert(struct TreeNode *root, int key)
{
if ( root == NULL )
{
root = (TreeNode **)malloc(sizeof(TreeNode *) * num_of_keys);
root->keys[0] = key;
root->num_of_keys = root->num_of_keys - 1;
}
else
{
for ( s=0; (s<root->num_of_keys); s++ );
{
if ( key == root->keys
return NULL;
else
{
if (key<root->keys
keys[s+1] = keys
else{
key[s+1] = key;
s = s+1;
}
}
}
}
}
