public class Tree<T> extends java.lang.Object implements java.lang.Iterable<T>, Visitable<Tree<T>>
| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<Tree<T>> |
children
Holds the children
|
protected T |
element
Holds the node
|
protected Tree<T> |
parent
Points to the parent
|
| Constructor and Description |
|---|
Tree()
Constructs an empty tree with a null element
|
Tree(T element)
Constructs a tree with a node element
|
Tree(T element,
java.util.List<Tree<T>> children)
Constructs a tree with a node element and children
|
Tree(Tree<T> parent,
T element)
Constructs a tree with a node element and a parent
|
Tree(Tree<T> parent,
T element,
java.util.List<Tree<T>> children)
Constructs a tree with a node element and a parent
|
| Modifier and Type | Method and Description |
|---|---|
void |
addChild(Tree<T> child)
Adds a child
|
java.util.List<Tree<T>> |
getChildren()
Depth first search across the tree
|
T |
getElement()
Returns the element
|
Tree<T> |
getParent()
Returns the parent
|
java.util.Iterator<T> |
iterator() |
static void |
main(java.lang.String[] args) |
boolean |
receive(Visitor<Tree<T>> visitor)
Receives a visitor for a depth first traversal
|
void |
setChildren(java.util.List<Tree<T>> children)
Sets the children
|
void |
setElement(T element)
Sets the element
|
void |
setParent(Tree<T> parent)
Sets the parent
|
java.lang.String |
toString() |
protected T element
public Tree()
public Tree(T element)
public Tree(T element, java.util.List<Tree<T>> children)
public T getElement()
public void setElement(T element)
public java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>public boolean receive(Visitor<Tree<T>> visitor) throws java.lang.Exception
public java.lang.String toString()
toString in class java.lang.Objectpublic static void main(java.lang.String[] args)