Saturday 15 April 2017

implementing Left-pointer info right-pointer for java binary tree

i have been assigned a hw assignment about converting a list into a binary tree that i am having trouble wrapping my head around the concept, I have been reading through examples but i cant figure out how to actually use it. I need a left node pointer, information, and right pointer. I have found code to add but dont understand how to use it.

class Node{ int data; Node left; Node right; public Node(int data){ this.data = data; left = null; right = null; }

is this all i need to do my program, i dont understand how im suppose to assign left and right values to each node. Do i need a name for each node i insert. I have psuedo code for my hw such as

y=avail;  //whats avail? this is my first line
treeRoot = y;
info(y) = x[2];   //(im inputing from an array) how do i assign this?
lptr(y)=z;     // (left pointer of y gets z) z maybe a pointer?



via Tim E

No comments:

Post a Comment