The variable some_key contains the value (or key) to be inserted into the array the_keys
Empty slots will contain a value less than zero, there is room in the array (duh) for the new item
Can be solved with if statements or a loop, there are at most 2 items in a 234 Tree node before this insert
This is what I have. I know some of the parts are really redundant but there is no way of telling what the array is filled with or knowing what/where they are at.
The alg i'm trying to write is sweep left to right, if -1 and less then the next insert else insert. However, this has not been working when checking against his random, yes, random compiler which places -1 in different locations every check.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
if((the_keys[0] == -1) && (some_key < the_keys[1])) // stay left
{
the_keys[0] = some_key ;
}
elseif((the_keys[1] == -1) || (the_keys[2] == -1)) // check middle
{
if((the_keys[1] == -1) && (the_keys[2] == -1)) // if last is empty then insert into middle
the_keys[1] = some_key ;
elseif(some_key < the_keys[2]) // check key is less than last slot
the_keys[1] = some_key ;
else
the_keys[2] = some_key ;
}
His message when checking
The incorrect values found 19, 57, 24 should be 19, 24, 57