"1. Write a static function convertLink that receives a binary tree in sequential representation (Array SR and the index last) and returns the root of the tree in linked representation.
2. Write a static function convertSequential that receives the root of a binary tree in linked representation and returns the sequential representation of the tree (i.e. the array SR and the index last). The maximum size of the array SR may be computed by using another function computeLevel that computes the number of levels in the received tree.
Test the above two function as follows:
1. Draw a random binary tree with at least 15 nodes
2. Draw the sequential representation of the tree. So you have its array SR and
its index last.
3. Call the function convertLink for the sequential representation computed in the previous step.
4. Call the function convertSequential for the root computed in the previous step. You should obtain exactly the same sequential representation of step#2. "
my teacher is saying we don't even need to really implement a binary tree class... just the dummy node
so i have the node class something like
I'm having trouble with just the first function algorithm for "convertLink"........
say i have a binary tree that looks like this:
/ \ / \
D E F G
the array i would receive as a parameter would contain
0 1 2 4 5 6 7
A B C D E F G
Arrayname = BTarray
This is where I’m stuck and am desperate for help……… I’m thinking I have to make an “insert” function??
Say in my convert-to-link function I have a for loop
For(int a=0, a<last index of array; a++)
Void Insert (Node node, char value)
If(node.left != NULL)
If(node.right != NULL)
If(both right and left != NULL)
So… that would give me:
I’m really stuck here in that I don’t know how to make a function or algorithm that can reach the D, E, F, G etc………
The teacher went over the assignment real briefly in class and said this function is really really easy and everyone seemed to agree so I feel like I’m making this too complicated and I’m totally missing something??
Or if I’m not… how can I make the rest of my Insert function keep adding to the binary tree.. really desperate here.. due tomorrow
PS - I could be wrong in anything i wrote here... as in i could be writing my original sequential array completely wrong or something... i'm really lost so i'm open to anything.... maybe if i'm going about this completely wrong I can use some suggestions too