I need some help brainstorming an algorithm for implementing a given array into a BST array.
This is what I am stuck with using:
My example array is "val[-1,4,2,1,3,6,5,7]" and I need to omit -1 and put the rest of the values correctly in a BST array "bst[4 2 6 1 3 5 7]". However, the bst array is first initialized to "bst[-1 -1 -1 -1 -1 -1 -1]". For some reason these arrays are global, too.
My function call can only have two parameters in the main function: addBST(1, val[i]);
This is what I'm thinking..
addBST(int root, int newNode)
function call one:
if val[root] == -1
bst[root-1] = val[root+1];
function call two:
if newNode < bst[root-1]
if (bst[(root-1)*2+1] == -1)
{ bst[(root-1)*2+1] = newNode }
else
addBST(bst[(root-1)*2+1], newNode)
This is what I have brainstormed so far. I would like some advice from experienced C programmers. Thanks in advance, friends.



LinkBack URL
About LinkBacks


