|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.bfh.algo.example.TreeExample
public class TreeExample
This file contains some examples of the use of the
Forest
and the BinaryForest
interfaces.
Constructor Summary | |
---|---|
TreeExample()
|
Method Summary | |
---|---|
static void |
branchAllRoots(Forest<String> f,
String root)
This method creates a new node containing the value given as the root . |
static void |
displayBinaryForest(BinaryForest<String> f)
The displayBinaryForest method implements a
recursive in-order traversal. |
static void |
displayForest(Forest<String> f)
This method displays all the nodes of a forests f
This function contains a loop on all the roots of the
forest. |
static void |
ex1()
The ex1 method executes all tests concerning the Forest . |
static void |
ex2()
The ex2 method contains the tests about the BinaryForest . |
static BinaryForest<String> |
initBinaryForest()
The initBinaryForest method is used to create a new binary forest. |
static Forest<String> |
initForest()
This method creates and initialize a Forest. |
static void |
main(String[] args)
|
static void |
transferChildren(Forest<String> f,
Position<String> p1,
Position<String> p2)
This method transfers all the children from the node p1 to the node p2 . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TreeExample()
Method Detail |
---|
public static void displayForest(Forest<String> f)
f
This function contains a loop on all the roots of the
forest. Once a root is visited, all its subtree is displayed
(preorder-traversal).
f
- Forest the forest to be displayed.public static void branchAllRoots(Forest<String> f, String root)
root
. Then all the root nodes of the forest
f
are branched as children of this new node. The
result is a forest containing only one single tree whose root
is the new node.
f
- a Forest
root
- a String
value that will label the new
node to be created.public static void transferChildren(Forest<String> f, Position<String> p1, Position<String> p2)
p1
to the node p2
. This means we transfer all the subtrees whose roots are children of p1
under p2
.
f
- Forest
The forest in which the nodes are. All node need to be in the same forest.p1
- The Position
(i.e. node) that has childrenp2
- the second node, that will receive the children of
p1
.public static Forest<String> initForest()
DefaultForest
, but
manipulates and returns only a Forest
.
Forest
public static void displayBinaryForest(BinaryForest<String> f)
displayBinaryForest
method implements a
recursive in-order traversal.
The aim of this method is to display the binary trees in a way
that is familiar to us (with the root in the middle).
f
- the BinaryForest
that has to be displayed.public static BinaryForest<String> initBinaryForest()
initBinaryForest
method is used to create a new binary forest. That forest contains some nodes and they are grouped into different binary trees.
BinaryForest
.public static void ex1()
ex1
method executes all tests concerning the Forest
.
public static void ex2()
ex2
method contains the tests about the BinaryForest
.
public static void main(String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |