An abbreviated version of the classes
BinaryTreeNode and
LinkedBinaryTree
of the text is given below.
public class BinaryTreeNode
{
// package visible data members
Object element;
BinaryTreeNode leftChild; // left subtree
BinaryTreeNode rightChild; // right subtree
}
public class LinkedBinaryTree
{
// instance data member
BinaryTreeNode root; // root node
public void swapChildren()
{
// code for this method comes here
}
}
The method swapChildren swaps the
left and right children of every node in the binary tree this.
- (a)
-
[8]
Write Java code for the method
swapChildren.
You may define and implement new private
member methods as needed.
You may not create or delete any nodes or invoke any binary tree methods
not defined in this problem unless you provide code for these methods.
- (b)
-
[2] What is time complexity of your code as a function
of the number of nodes in the binary tree?