public class Tree<T> extends Object implements Iterable<T>, Visitable<Tree<T>>
| Modifier and Type | Field and Description |
|---|---|
protected 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,
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,
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
|
List<Tree<T>> |
getChildren()
Depth first search across the tree
|
T |
getElement()
Returns the element
|
Tree<T> |
getParent()
Returns the parent
|
Iterator<T> |
iterator() |
static void |
main(String[] args) |
boolean |
receive(Visitor<Tree<T>> visitor)
Receives a visitor for a depth first traversal
|
void |
setChildren(List<Tree<T>> children)
Sets the children
|
void |
setElement(T element)
Sets the element
|
void |
setParent(Tree<T> parent)
Sets the parent
|
String |
toPrettyString()
Prints a tree with visualization of its structure.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorprotected T element
public Tree()
public Tree(T element)
public Tree(T element, List<Tree<T>> children)
public T getElement()
public void setElement(T element)
public boolean receive(Visitor<Tree<T>> visitor) throws Exception
public String toPrettyString()
public static void main(String[] args)
Copyright © 2018. All rights reserved.