|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.pow2.structures.tree.BinaryTree
Binary tree abstract class.
Extend this class and implement the build method.
| Field Summary | |
protected org.apache.log4j.Category |
cat
Log4j category |
static int |
INTRAVERSE
use this value to specify the in-traverse algorithm |
protected NodeVisitorInterface |
nodeVisitor
the nodeVisitor reference |
static int |
POSTRAVERSE
use this value to specify the post-traverse algorithm |
static int |
PRETRAVERSE
use this value to specify the pre-traverse algorithm |
protected Node |
root
The root node of the tree |
protected int |
traverseMode
Specify the tree traverse mode. |
| Constructor Summary | |
BinaryTree()
Default constructor for the BinaryTree object. |
|
BinaryTree(Object o)
Constructor for BinaryTree object. |
|
| Method Summary | |
boolean |
addLeft(Node p,
Node c)
Add a new left node to the parent node left node list. |
boolean |
addRight(Node p,
Node c)
Add a new right node to the parent node right node list. |
abstract void |
build()
Build the tree. |
Object |
getData()
Gets the data object of the tree root node |
Node |
getLeft()
Gets the left node of the root node |
NodeVisitorInterface |
getNodeVisitor()
Gets the nodeVisitor attribute of the BinaryTree object |
Node |
getRight()
Gets the right node of the root node |
Node |
getRoot()
Get the root node of the BinaryTree object |
int |
getTraverseMode()
Get the traverse mode attribute of the BinaryTree object. |
boolean |
insertLeft(Node p,
Node c)
Insert a new left node into the tree. |
boolean |
insertRight(Node p,
Node c)
Insert a new right node into the tree. |
protected void |
intrav(Node p)
Traverse the tree, using in-order algorithm, starting from the input node. |
boolean |
isEmpty()
Test if the Binary Tree is empty. |
void |
move(Node p,
Node c,
boolean isLeft)
Move the input c node
over the new parent p node. |
protected void |
postrav(Node p)
Traverse the tree, using post-order algorithm, starting from the input node. |
protected void |
pretrav(Node p)
Traverse the tree, using pre-order algorithm, starting from the input node. |
protected void |
remove(Node n)
Remove the input node from the tree, rearranging the parent and the child nodes references. |
void |
remove(Node n,
boolean recursive)
Remove the input node from the tree. |
void |
setData(Object o)
Sets the data object of the tree root node. |
void |
setNodeVisitor(NodeVisitorInterface nodeVisitor)
Sets the nodeVisitor attribute of the BinaryTree object |
void |
setRoot(Node r)
Set the root node of the BinaryTree object |
void |
setTraverseMode(int traverseMode)
Set the traverseMode attribute of the BinaryTree object. |
void |
traverse()
Traverse the tree, using the traverse algorithm specified using setTraverseMode. |
void |
visit(Node n)
Visit the content of the input node. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int PRETRAVERSE
public static final int INTRAVERSE
public static final int POSTRAVERSE
protected org.apache.log4j.Category cat
protected Node root
protected int traverseMode
protected NodeVisitorInterface nodeVisitor
| Constructor Detail |
public BinaryTree()
PRETRAVERSE.
public BinaryTree(Object o)
object as the data object
related to the root node of the tree.
o - the data object to relate to the tree root node| Method Detail |
public abstract void build()
public void setData(Object o)
o - The new root node data objectpublic void setNodeVisitor(NodeVisitorInterface nodeVisitor)
nodeVisitor - The new nodeVisitor valuepublic void setRoot(Node r)
r - The new root valuepublic void setTraverseMode(int traverseMode)
traverseMode can have one of the following values:
BynaryTree.PRETRAVERSE to use the pre-traverse algorithmBynaryTree.INTRAVERSE to use the in-traverse algorithmBynaryTree.POSTRAVERSE to use the post-traverse algorithm
traverseMode - the traversing mode.public boolean isEmpty()
public Object getData()
public NodeVisitorInterface getNodeVisitor()
public Node getLeft()
public Node getRoot()
public Node getRight()
public int getTraverseMode()
public boolean insertLeft(Node p,
Node c)
p - the parent node where to insert the new left nodec - the new left node to add to the parent node
public boolean insertRight(Node p,
Node c)
p - the parent node where to insert the new right nodec - the new right node to add to the parent node
public boolean addLeft(Node p,
Node c)
p - the parent nodec - the left node to add to the parent node left node list
public boolean addRight(Node p,
Node c)
p - the parent nodec - the node to add to the the parent node right node list
public void move(Node p,
Node c,
boolean isLeft)
c node
over the new parent p node.
p - the new parent node for c nodec - the node to moveisLeft - true if c must be inserted
as a left node of p;
false if c must be inserted as right
node of p
public void remove(Node n,
boolean recursive)
n - the node to removerecursive - true to remove all the input node children;
false otherwiseprotected void remove(Node n)
n - the node to remove
public void traverse()
throws Exception
setTraverseMode.
Exception - if any error occurs
protected void pretrav(Node p)
throws Exception
p - the node where to start the tree traversing
Exception - if any error occurs
protected void intrav(Node p)
throws Exception
p - the node where to start the tree traversing.
Exception - if any error occurs
protected void postrav(Node p)
throws Exception
p - the node where to start the tree traversing.
Exception - if any error occurs
public void visit(Node n)
throws Exception
n - the node to visit
Exception - if any error occurs
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||