public class Btree<E>
extends java.lang.Object
Constructor and Description |
---|
Btree() |
Modifier and Type | Method and Description |
---|---|
static <E> void |
inorder(btree.BTnode<E> root,
btree.BTnode.Visitor<E> visitor)
Uses an inorder traversal to process the data from each node
at or below this node of the binary tree.
|
static <E> void |
inorderPrint(btree.BTnode<E> root)
Uses an inorder traversal to print the data from each node at or below
this node of the binary tree.
|
static <E> boolean |
isLeaf(btree.BTnode<E> node)
Accessor method to determine whether a node is a leaf.
|
static <E> void |
postorderPrint(btree.BTnode<E> root)
Uses a postorder traversal to print the data from each node at or below
this node of the binary tree.
|
static <E> void |
preorderPrint(btree.BTnode<E> root)
Uses an preorder traversal to print the data from each node at or below
this node of the binary tree.
|
void |
print(btree.BTnode<E> root,
int depth)
Uses an inorder traversal to print the data from each node at or below
this node of the binary tree, with indentations to indicate the depth
of each node.
|
static void |
printMany(int count,
java.lang.String s)
prints a string as many times as specified and doesn't end line
|
static <E> void |
printSideways(btree.BTnode<E> root,
int depth)
Uses a right-to-left inorder traversal to print the data from each
node at or below this node of the binary tree, with indentations to
indicate the depth of each node.
|
static <E> btree.BTnode<E> |
treeCopy(btree.BTnode<E> source)
Copy a binary tree.
|
static <E> long |
treeSize(btree.BTnode<E> root)
Count the number of nodes in a binary tree.
|
public static <E> void inorderPrint(btree.BTnode<E> root)
-
- none
Postcondition:
The data of this node and all its descendants have been written by
System.out.println( ) using an inorder traversal.public static <E> void inorder(btree.BTnode<E> root, btree.BTnode.Visitor<E> visitor)
-
- none
Postcondition:
The data of this node and all its descendants have been handled by
the provided visitor method using an inorder traversal.public static <E> void postorderPrint(btree.BTnode<E> root)
-
- none
Postcondition:
The data of this node and all its descendants have been written by
System.out.println( ) using a postorder traversal.public static <E> void preorderPrint(btree.BTnode<E> root)
-
- none
Postcondition:
The data of this node and all its descendants have been written by
System.out.println( ) using an inorder traversal.public static <E> boolean isLeaf(btree.BTnode<E> node)
-
- node
the node that is possibly a leafpublic void print(btree.BTnode<E> root, int depth)
root
- the root node of this subtreedepth
- the depth of this node (with 0 for root, 1 for the root's
children, and so on)
Precondition:
depth is the depth of this node.
Postcondition:
The data of this node and all its descendants have been written by
System.out.println( ) using an inorder traversal.
The indentation of each line of data is four times its depth in the
tree. A dash "--" is printed at any place where a child has no
sibling.
This is Michael Main's code adapted to having a node parameter.public static void printMany(int count, java.lang.String s)
count
- the number of times t print strings
- the string to print multiple timespublic static <E> void printSideways(btree.BTnode<E> root, int depth)
root
- the root of this subtreedepth
- the depth of this node (with 0 for root, 1 for the root's
children, and so on)
Precondition:
depth is the depth of this node.
Postcondition:
The data of this node and all its descendants have been writeen by
System.out.println( ) using an inorder traversal.
The indentation of each line of data corresponds to its depth in the
tree. A tilde "~" is printed at any place where a child has no
sibling.
Based on the C++ binary tree print by Michael Mainpublic static <E> btree.BTnode<E> treeCopy(btree.BTnode<E> source)
source
- a reference to the root of a binary tree that will be copied
(which may be an empty tree where source is null)java.lang.OutOfMemoryError
- Indicates that there is insufficient memory for the new tree.public static <E> long treeSize(btree.BTnode<E> root)
root
- a reference to the root of a binary tree (which may be
an empty tree where source is null)