|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sourceforge.cilib.type.types.container.AbstractTree<E>
net.sourceforge.cilib.type.types.container.BinaryTree<E>
E - The Comparable and Cloneable type.public class BinaryTree<E extends Comparable<? super E> & Cloneable>
Implementation of a BinaryTree.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class net.sourceforge.cilib.type.types.container.AbstractTree |
|---|
AbstractTree.TreeIterator |
| Field Summary |
|---|
| Fields inherited from class net.sourceforge.cilib.type.types.container.AbstractTree |
|---|
key |
| Constructor Summary | |
|---|---|
BinaryTree()
Create a new instance of BinaryTree. |
|
BinaryTree(BinaryTree<E> copy)
Copy constructor. |
|
BinaryTree(E element)
Create a new instance of BinaryTree with the provided parameter as the value of the key. |
|
BinaryTree(E key,
BinaryTree<E> left,
BinaryTree<E> right)
Create an instance of BinaryTree with the provided tree instances as the left and right children, maintaining the provided key value. |
|
| Method Summary | |
|---|---|
boolean |
add(E element)
Convenience method. |
boolean |
addSubTree(Tree<E> subTree)
Add the provided subtree to the current Tree. |
void |
clear()
Clear all contained object instances from the current Structure. |
boolean |
contains(E element)
Determine if element is contained within the Structure. |
void |
depthFirstTraversal(PrePostVisitor<E> visitor)
Perform a depth first traversal of the current Tree node, executing the operation stored within the provided Visitor instance. |
boolean |
equals(Object obj)
Compare the specified object with this type for equality. |
BinaryTree<E> |
getClone()
Create a cloned copy of the current object and return it. |
int |
getDegree()
Get the degree of the current Tree. |
Tree<E> |
getSubTree(E element)
Get the subtree with the specified key value. |
Tree<E> |
getSubTree(int index)
Return the subTree with the node value of element. |
int |
hashCode()
Returns the hash code value for this list. |
boolean |
isLeaf()
Determine if the current Tree node is a leaf node in the current structure. |
boolean |
remove(E element)
Remove the first element found within the Structure. |
E |
remove(int index)
Remove the object at the specified index. |
Tree<E> |
removeSubTree(E element)
Remove the subtree with the given key value. |
Tree<E> |
removeSubTree(int index)
Remove the subtree at the specified index within the current Tree. |
String |
toString()
|
| Methods inherited from class net.sourceforge.cilib.type.types.container.AbstractTree |
|---|
accept, addAll, breadthFirstTraversal, getKey, getRepresentation, isEmpty, iterator, randomize, removeAll, setKey, size |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public BinaryTree()
public BinaryTree(E element)
element - The value of the key that the BinaryTree should maintain.
public BinaryTree(E key,
BinaryTree<E> left,
BinaryTree<E> right)
key - The value of the tree to maintain.left - The left child.right - The right child.public BinaryTree(BinaryTree<E> copy)
copy - The instance to copy.| Method Detail |
|---|
public BinaryTree<E> getClone()
getClone in interface StructuredType<E extends Comparable<? super E> & Cloneable>getClone in interface Tree<E extends Comparable<? super E> & Cloneable>getClone in interface TypegetClone in interface CloneablegetClone in class AbstractTree<E extends Comparable<? super E> & Cloneable>Object.clone()public boolean equals(Object obj)
true if and only if the specified object is also an instance
of the same type.
equals in interface Typeequals in class AbstractTree<E extends Comparable<? super E> & Cloneable>obj - The object to compare.
true if equality exists, false otherwise.Object.equals(Object)public int hashCode()
int hashCode = 7;
Iterator<E> i = list.iterator();
while (i.hasNext()) {
E obj = i.next();
hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
}
This ensures that type1.equals(type2) implies that
type1.hashCode()==type2.hashCode() for any two types,
type1 and type2, as required by the general
contract of Object.hashCode().
hashCode in interface TypehashCode in class AbstractTree<E extends Comparable<? super E> & Cloneable>Object.equals(Object),
Type.equals(Object)public String toString()
toString in class Objectpublic boolean addSubTree(Tree<E> subTree)
subTree - The to add.
public Tree<E> getSubTree(E element)
element - The value of the key to lookup.
null.public Tree<E> getSubTree(int index)
public Tree<E> removeSubTree(E element)
element - The value of the key of the subtree to be removed.
null.public Tree<E> removeSubTree(int index)
index - The index of the Tree to be removed.
null.public boolean add(E element)
BinaryTree#addSubtree(Tree).
element - The element to add to the current tree.
addSubTree(Tree).public void clear()
public boolean contains(E element)
element is contained within the Structure.
element - The object that is tested for containment.
true if the Structure contains the object,
false otherwise.public boolean remove(E element)
element found within the Structure.
element - The object to remove
true if the removal was successful, false otherwise.public E remove(int index)
index.
index - The index at which an object is to be removed.
public void depthFirstTraversal(PrePostVisitor<E> visitor)
depthFirstTraversal in interface Tree<E extends Comparable<? super E> & Cloneable>depthFirstTraversal in class AbstractTree<E extends Comparable<? super E> & Cloneable>visitor - The visitor operation to execute at each node.public boolean isLeaf()
true if it is a leaf node, false otherwise.public int getDegree()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||