domingo, 13 de abril de 2008

BinaryTree in Java, part II

Ok, now i am going to explain whats methods we will implements to complete the documentation of the BinaryTree. Our class implementes the Iterator interface and must to have an internal class which do this job, but we will forget that at the moment.

int size()
Returns the nodes number tree.

Iterator iterator()
Returns the iterator which recover the tree.

boolean equals(Object bt)
Returns a true value, if the BinaryTree has the same structure and elements of the tree from the input parameter.

Object getRoot()
Returns the BinaryTree root (The info at the node). If the tree is null, throws the NoSuchElementException.


BinaryTree left()
Returns the BibaryTree from the son left. If the tree is leaf, throws an EmptyTreeException.

BinaryTree right()
Returns the BibaryTree from the son right. If the tree is leaf, throws an EmptyTreeException


void setRoot(Object root)
It sets a new Object in the root info. If the tree is null, it throws a NoSuchElementException.

void remove(boolean left)
If the parameter left is true, the "remove" deletes the left son. In other case, the right son will be deleted. If the tree is null, it throws an EmptyTreeException.

void set(boolean left,BinaryTree t)
If the parameter left is true, it sets the BinaryTree from the parameter in the left son. In other case, it sets the tree like right son. If the tree is null, it throws an EmptyTreeException.

boolean isLeaf()
If the tree is leaf, it returns the value true. Its throws EmptuTreeException if the tree is null.

boolean isEmpty()
Returns a true value if the tree has not childrens.

Iterator iterator(String it)
Returns an iterator “PREORDER”, “INORDER” or “POSORDER".

No hay comentarios: