This classwork focuses on implementing trees. Start by snarfing the code under classwork-rodger/12ClwkTrees.
Turn this classwork by submitting it to Clwk12Trees
The first code we will look at is TreeStuff.java which involves trees.
Here is a Node for a Tree
Thanks to Nick Parlante for this problem.
In a binary search tree, each node contains a single data element and
"small" and "large" pointers to sub-trees (i.e. left
and
right
). A binary tree with the values 1
through 5 may be defined as follows:
Now, consider the data as a circular doubly linked list.
The challenge is to take an ordered binary tree and rearrange the internal pointers to make a circular doubly linked list out of it. The left pointer should play the role of prev and the right pointer should play the role of next. The list should be arranged so that the nodes are in increasing order.
treeToList(TreeNode root)
that takes an ordered
binary tree and rearranges the internal pointers to make a circular
doubly linked list out of the tree nodes. The left pointers
work like the prev field in a doubly linked list and the
right pointers work
similar to the next field. The list should be arranged so that the
nodes are in increasing order. Return the head pointer to the new
list. The operation can be done in O(n) time -- essentially operating
on each node once.
Turn this classwork by submitting it to Clwk12Trees