|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--BinaryTreePlus
Class BinaryTreePlus is an extended version of the plain BinaryTree class. BinaryTree plus adds some additional traversal methods, as discussed in CSC 103 Lecture Notes week 4.
Field Summary | |
protected BinaryTreePlusNode |
root
The root of this tree |
protected int |
size
The size of this tree, i.e., the number of nodes it contains |
protected BinaryTreePlusNode[] |
stack
Traversal stack |
protected int |
STACK_SIZE
Size of traversal stack, good for trees depths up to 100 |
protected int |
stackIndex
Current stack index |
Constructor Summary | |
BinaryTreePlus(BinaryTreePlusNode root)
Construct this with the given node as the root. |
Method Summary | |
void |
addTreeModelListener(javax.swing.event.TreeModelListener l)
This is a TreeModel method we don't care about. |
protected boolean |
emptyStack()
|
BinaryTreePlusNode |
find(java.lang.Object value)
Return a pointer to the first node containing the given value, using a preorder traversal. |
protected BinaryTreePlusNode |
findPreorder(java.lang.Object value,
BinaryTreePlusNode t)
Recursive work doer for find. |
java.lang.Object |
getChild(java.lang.Object parent,
int index)
If the given index = 0, return the left child of the given parent, otherwise return the right child. |
int |
getChildCount(java.lang.Object parent)
Return 0 if the given parent object is a leaf node, return 2 otherwise. |
int |
getIndexOfChild(java.lang.Object parent,
java.lang.Object child)
Return 0 or 1 based on whether the given child is the right or left child of the given parent. |
java.lang.Object |
getRoot()
Return the root of this tree. |
boolean |
isLeaf(java.lang.Object node)
Return true if the given node is a leaf, false if not. |
protected BinaryTreePlusNode |
pop()
Push from a simple array-based stack. |
protected void |
push(BinaryTreePlusNode t)
Push onto a simple array-based stack. |
void |
removeTreeModelListener(javax.swing.event.TreeModelListener l)
This is a TreeModel method we don't care about. |
java.lang.String |
toString()
Convert this to a preorder string of the form: root left subtree ... |
protected static java.lang.String |
toString(BinaryTreePlusNode t,
int indent)
Recursive work doer for toString(), converting the given node value to a string, preceded by indent spacing, followed by the recursive toString of the left and right subtrees. |
java.lang.String |
traversePreorder(BinaryTreePlusNode t)
Perform a very basic recursive preorder traversal, returning a space-delimited string of the node values. |
java.lang.String |
traverseWithNestedLoop()
Attempt to perform an iterative preorder tree traversal using a doubly nested loop. |
java.lang.String |
traverseWithStack()
Perform an iterative preorder tree traversal using an explicit stack. |
void |
valueForPathChanged(javax.swing.tree.TreePath path,
java.lang.Object newValue)
This is a TreeModel method we don't care about. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected BinaryTreePlusNode root
protected int size
protected BinaryTreePlusNode[] stack
protected int stackIndex
protected final int STACK_SIZE
Constructor Detail |
public BinaryTreePlus(BinaryTreePlusNode root)
Method Detail |
public BinaryTreePlusNode find(java.lang.Object value)
protected BinaryTreePlusNode findPreorder(java.lang.Object value, BinaryTreePlusNode t)
public java.lang.String toString()
toString
in class java.lang.Object
protected static java.lang.String toString(BinaryTreePlusNode t, int indent)
public java.lang.String traversePreorder(BinaryTreePlusNode t)
public java.lang.String traverseWithNestedLoop()
public java.lang.String traverseWithStack()
protected void push(BinaryTreePlusNode t)
protected BinaryTreePlusNode pop()
protected boolean emptyStack()
public java.lang.Object getChild(java.lang.Object parent, int index)
getChild
in interface javax.swing.tree.TreeModel
public int getChildCount(java.lang.Object parent)
getChildCount
in interface javax.swing.tree.TreeModel
public int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
getIndexOfChild
in interface javax.swing.tree.TreeModel
public java.lang.Object getRoot()
getRoot
in interface javax.swing.tree.TreeModel
public boolean isLeaf(java.lang.Object node)
isLeaf
in interface javax.swing.tree.TreeModel
public void addTreeModelListener(javax.swing.event.TreeModelListener l)
addTreeModelListener
in interface javax.swing.tree.TreeModel
public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
removeTreeModelListener
in interface javax.swing.tree.TreeModel
public void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
valueForPathChanged
in interface javax.swing.tree.TreeModel
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |