Binary tree
You can find an excellent graphical representation of Preorder, Postorder and Inorder traversal of a binary tree here.
Psuedocode for inserting values into a binary tree. Assume that you are creating a binary tree for integers.
Psuedocode for inserting values into a binary tree. Assume that you are creating a binary tree for integers.
/* n is the root node of the binary tree
** value is the integer to be inserted into binary tree
*/
insertTree(Node n, int value) {
if (value < n.value) {
if n.left != null
insertTree(n.left, value);
else
n.left = new Node(value);
return;
}
else {//value > n.value
if n.right != null
insertTree(n.right, value);
else
n.right = new Node(value);
return;
}
}
0 Comments:
Post a Comment
<< Home