Llamaremos a un árbol de tal generalidad, un árbol libre ( free tress ).
Veamos algunos ejemplos donde la estructura de datos árbol puede ser muy util :
*---* *---* *---* *---*
| A | | A | | A | | A | ......... Nivel 1
*---* *---* *---* *---*
||| ||| |
+-------+|+------+ +-------+|+------+ |
| | | | | | |
*---* *---* *---* *---* *---* *---* *---*
| B | | C | | D | | D | | C | | B | | B | ......... Nivel 2
*---* *---* *---* *---* *---* *---* *---*
| | | | | | |
+--+ +--+ | | +--+ +--+ |
| | | | | | |
*---* *---* *---* *---* *---* *---* *---*
| E | | F | | G | | G | | E | | F | | C | ......... Nivel 3
*---* *---* *---* *---* *---* *---* *---*
Arbol 1 Arbol 2 Arbol 3 Arbol 4
(A(B(E),C(F,G(K,L))),D(H,I,J)))
*---* .............................................................
| A | . ................ .
*---* . . . .
||| . . ..... . .
+---------+|+---------------+ . A . B . E . . .
| | | . . ..... . .
*---* *---* *---* . . . .................... . ....................
| B | | C | | D | . ................ . . . . .
*---* *---* *---* . ................................ . ..... . . . 3 7 6 .
| | | ||| . . ................ . . D . H . . . . .
| +--+ +--+ +-----+|+-----+ . . . . . . ..... . . . 4 ....................
| | | | | | . . C . ..... . . . ..... ..... . . . . . .
*---* *---* *---* *---* *---* *---* . . . G . K . . . . . J . . I . . . . 9 . 1 . .
| E | | F | | G | | H | | I | | J | . . . ..... . . . ..... ..... . . . . 5 . 11 .
*---* *---* *---* *---* *---* *---* . . . ..... . . . . . . . . .
| | . . ..... . . L . . . .................... . .................... .
+--+ +--+ . . . F . . ..... . . . . .
| | . . ..... . . . . . 2 8 10 .
*---* *---* . . ................ . . . .
| K | | L | . ................................ . ....................
*---* *---* .............................................................
Arbol 5 Arbol 5 - Conjuntos Disjuntos Conjuntos No Disjuntos
Observar que el árbol 1 es una árbol distinto del árbol 2 en términos de
árboles ordenados, pero es el mismo árbol si hablamos de árboles desordenados.
El árbol 5 ha sido representado según su disposición tradicional y otra
que muestra el concepto de conjuntos disjuntos que conforman al árbol
mencionado. A modo de ejemplo, se muestra a la derecha del árbol 5, conjuntos
no disjuntos, para apreciar la diferencia.
Es conveniente tener una representación gráfica de un nodo de un árbol.
El el siguiente bosquejo pretendemos representar el enlace a su padre,
el conjunto de datos que contiene el nodo y los enlaces a cada uno de sus
hijos.
Nodo A
*---------------------------------------* *---------------*
| | | *---* |
| *---* | | | 0 | |
| | | | Padre ............>| *---* |<............
| *---* | Campo de enlace . | *---*---* | .
| | *---* . | | . | . | | .
| | | A | . | *-.-*-.-* | .
| *---------- ..... ----------* | *---* . *-----.---.-----* . Para simplificar
| | | | | | | | Datos | | . . . . el dibujo no hemos
| *---------- ..... ----------* | Campos de informacion +--+ +--+ *--.------------* . . *------------.--* representado los
| | | | | . *---* | . . C | *---* . | campos de informacion
| | *---* *---* | ...... | | . . | | ...... |
| *-------------- ..... --------------* | | B | | C | | *---* |<..... .....>| *---* |
| | | | | | | | | | Hijos *---* *---* | *---* | | *---* |
| *-------------- ..... --------------* | Campos de enlaces | | 0 | | | | 0 | |
| | | *---* | | *---* |
*---------------------------------------* *---------------* *---------------*
Arbol 6 Nodo B Arbol 6 Nodo C
Cabe acotar que en el caso que el nodo sea declarado como hoja debera
contar con un campo adicional, booleano, para indicar de que se trata
de una hoja o de una rama.
Observar que los campos hijos no indican de que se trate de una hoja, ya
que puede ser una rama, aun sin hijos.
Las interfases describen la funcionalidad de una estructura de datos, sin
hacer mención alguna a la forma de implementación, inclusive a la creacion
de los objetos.
La interfase de nodos que no pueden cambiar ( TreeNode Interfase ), o nodos no mutantes es :
La interfase de nodos que si pueden cambiar ( MutableTreeNode Interfase ), limitando sus cambios a
agregado o eliminación de hijos y cambio de los datos almacenados en el nodo,
es :
En la representacion por filas no hay mas de un nodo por fila. Esta representacion es muy usada en interfases graficas de computadoras.
Level Level Level Level Level Level Level Level Level Level
1 2 3 1 2 3 1 1 2 3
*---* *---* *---* *---*
| A | | A | | A | | A |
*---* *---* *---* *---*
| *---* | *---* | *---*
+----| B | +----| D | +----| B |
| *---* | *---* *---*
| | *---* | | *---* | *---*
| +----| E | | +----| G | +----| C |
| | *---* | *---* *---*
| | *---* | *---*
| +----| F | +----| C |
| *---* | *---*
| *---* | *---*
+----| C | +----| B |
| *---* *---*
| *---* | *---*
+----| D | +----| E |
*---* | *---*
| *---* | *---*
+----| G | +----| F |
*---* *---*
Arbol 1 Arbol 2 Arbol 3 Arbol 4
Level Level Level Level Level Level Level Level Level Level
1 2 3 1 2 3 1 2 3 1
*---* *---* *---* *****
| A | | A | | A | * A *
*---* *---* *---* *****
| *---* | *---* | *---*
+----| B | +----| B | +----| B |
| *---* | *---* | *---*
| | *---* | | *---* | | *---*
| +----| E | | +----| E | | +----| E |
| *---* | *---* | *---*
| *---* | ***** | *---*
+----| C | +----* C * +----| C |
| *---* | ***** | *---*
| | *---* | ***** | | *---*
| +----| F | +----* D * | +----| F |
| | *---* ***** | | *---*
| | *---* | | *****
| +----| G | | +----* G *
| *---* | *****
| | *---* | *****
| +----| K | +----* D *
| | *---* *****
| | *---*
| +----| L |
| *---*
| *---*
+----| D |
*---*
| *---*
+----| H |
| *---*
| *---*
+----| I |
| *---*
| *---*
+----| J |
*---*
Arbol 5 Vista 1 Arbol 5 Vista 2 Arbol 5 Vista 3 Arbol 5 Vista 4
Las vistas 2, 3 y 4 del Arbol 5 muestran Nodos Ramas Colapsados, lo que
se indica como rectangulos de asteriscos.
Los Nodos Ramas Expandidos se muestran con rectangulos de rayas.
(A(B(E(K,L),F),C(G),D(H(M),I,J)))
*---*
| A | Nivel 1 Atomos
*---*
|||
+-----------+|+-----------+ Listas
| | |
*---* *---* *---*
| B | | C | | D | Nivel 2 Atomos
*---* *---* *---*
| | | |||
+----+ +----+ | +----+|+----+ Listas
| | | | | |
*---* *---* *---* *---* *---* *---*
| E | | F | | G | | H | | I | | J | Nivel 3 Atomos
*---* *---* *---* *---* *---* *---*
| | |
+----+ +----+ | Listas
| | V
*---* *---* *---*
| K | | L | | H | Nivel 4 Atomos
*---* *---* *---*
+---+---+---+ +---+---+---+ +---+---+---+ +---+---+---+
| 0 | A | ..|..>| 1 | . | ..|..................................................................>| 1 | . | ..|....>| 1 | . | 0 | Nivel 1
+---+---+---+ +---+---+---+ +---+---+---+ +---+---+---+
. . .
. . .
V V V
+---+---+---+ +---+---+---+ +---+---+---+
| 0 | B | ..|..>| 1 | . | ..|...................................| 1 | . | 0 | Nivel 2
+---+---+---+ +---+---+---+ +---+---+---+
. .
. .
V V
+---+---+---+ +---+---+---+ +---+---+---+ +---+---+---+
| 0 | E | ..|..>| 1 | . | ..|..>| 1 | . | 0 | | 0 | F | 0 | Nivel 3
+---+---+---+ +---+---+---+ +---+---+---+ +---+---+---+
. .
. .
V V
+---+---+---+ +---+---+---+
| 0 | K | 0 | | 0 | L | 0 | Nivel 4
+---+---+---+ +---+---+---+
El dibujo esta incompleto y se invita al alumno a
completar el dibujo de la representacion de un arbol con listas generalizadas.
Muchas veces existe la necesidad de :
Las soluciones a estas necesidades están regidas por la idea de transformar una
estructura de datos que es basicamente no lineal en una lineal. Obviamente
esta linealidad se logra sin alterar la estructura básica del árbol y
visitando todos los nodos del árbol, una sola vez a cada uno, en las
formas básicas.
A continuación siguen las formas básicas de recorrer, navegar o enumerar los
nodos de un árbol, las que veremos a través del siguiente árbol,
el que representa jerárquicamente, por ejemplo, las ciudades donde una empresa
tiene sus oficinas.
*---*
| | Mundo
*---*
| |
+----------------------------+ +----------------------------+
| |
*---* *---*
| | Argentina | | Chile
*---* *---*
| | | |
+---------------------------+ | +---------------------------+ |
| | | |
*---* *---* *---* *---*
| | Santa Fe | | Cordoba | | Chaco | | Region Metropolitana
*---* *---* *---* *---*
||||| ||| | | |
+---------+|||+---------+ ||| | | |
| +----+|+----+ | +----+|+----+ +----+ +----+ |
| | | | | | | | | | |
*---* *---* *---* *---* *---* *---* *---* *---* *---* *---* *---*
| | | | | | | | | | | | | | | | | | | V | | |
*---* *---* *---* *---* *---* *---* *---* *---* *---* *---* *---*
Rafae Rosar Santa Venad Villa Cordo CuraB RioCu Resis Villa Santi
Arbol 8
Se usa el metodo Enumeration breadthFirstEnumeration().
*---*
comienzo ........>>.....|.. |
*---*
|.|
+----------------------------+.+----------------------------+
....<<.....|.......<<...........<<........ |
. *---* *---*
....>>...|...|.....>>...........>>...............>>...........>>.....|...|......
*---* *---* .
| | | | .
+---------------------------+ | +---------------------------+ | .
....<<.....|......................<<.....|.......<<...........<<.......|.......<<...........<<.......|........
. *---* *---* *---* *---*
....>>...|...|....................>>...|...|.....>>...........>>.....|...|.....>>...........>>.....|...|......
*---* *---* *---* *---* .
||||| ||| | | | .
+---------+|||+---------+ ||| | | | .
| +----+|+----+ | +----+|+----+ +----+ +----+ | .
....<<.....|.....|.....|.....|.....|.....<<....|.....|.....|.......<<........|...........|.........<<............|........
. *---* *---* *---* *---* *---* *---* *---* *---* *---* *---* *---*
....>>...|...|.|...|.|...|.|...|.|...|...>>..|...|.|...|.|...|.....>>......|...|.......|...|.......>>..........|...|......>> terminacion
*---* *---* *---* *---* *---* *---* *---* *---* *---* *---* *---*
En esta navegacion de se debe utilizar una estructura de datos auxiliar, como ser
una lista, para identificar los nodos que ya han sido visitados.
Se usa el metodo Enumeration depthFirstEnumeration().
*---*
comienzo ...........>...| |....>......... terminacion
.*---*.
............................... | | ..................................
. +----------------------------+ +----------------------------+ .
. | | .
.*---* *---* .
.| |...>................................................. | |.>..
.*---*. . *---*.
...............................| | |...<.............................. . | .<..
. +---------------------------+ | +---------------------------+ . . | .
. | | | . . | .
.*---* *---* *---* . . *---* .
.| |..>......................| |..>......................| |..>. . | |.>..
.*---*. .*---*. .*---*. . *---*.
...............|||||..<............ ......... ||| ..<...... ......... | | ..<...... . | .
. +---------+|||+---------+ . . ||| . . | | . . | .<..
. | +----+|+----+ | . . +----+|+----+ . . +----+ +----+ . . | .
. | | | | | . . | | | . . | | . . | .
. *---* *---* *---* *---* *---* . . *---* *---* *---* . . *---* *---* . . *---* .
.>.|...|.|...|.|...|.|...|.|...|.>. .>.|...|.|...|.|...|.>. .>.|...|.......|...|.>. .>.|...|.>..
*---* *---* *---* *---* *---* *---* *---* *---* *---* *---* *---*
En este tipo de navegacion no necesito de una estructura de datos auxiliar
para navegar el arbol. Toda la informacion necesaria esta disponible en los nodos.
El dibujo esta muy simplificado, ya que muestra una travesia a traves de
hermanos en forma directa, cuando en la realidad no hay un pointer que permite
navegar de hermano a hermano. Lo que ocurre es que para ir al siguiente hermano
se debe volver al padre y alli si seguir al siguiente hermano. El siguiente
dibujo lo muestra con mas detalle.
V | A
. | .
. | .
.*-----*.
.| .>. |.
.*-----*.
........ |. .| ........
. |. .| .
. +----+. .+----+ .
. | . . | .
. *---* . . *---* .
..|...|.>.. ..>.|...|..
*---* *---*
Observar que en el recorrido Depth First paso por los nodos ramas dos veces, una cuando voy a ir a recorrer los hijos del nodo rama y otra, cuando termine de recorrer los hijos del nodo rama. Esto da lugar a dos variantes de este recorrido, que tienen que ver con el momento en que visito, o extraigo informacion del nodo rama.
Se usa el metodo Enumeration preorderEnumeration().
Visito el Nodo Rama antes de ir a visitar sus hijos.
*---*
comienzo ..........>>...|.. | ...>>........ terminacion
*---* .
.......................<<....|.| ...<<...........................
+----------------------------+ +----------------------------+ .
| | .
*---* *---* .
| . | .>....................................................|.. | .
*---* . *---* .
.....<....................<.|.| | .<............................. .<...| .
+---------------------------+ | +---------------------------+ . . | .
| | | . . | .
*---* *---* *---* . . *---* .
| . | .>....................>.|.. | .>....................>.|.. | . .>.|.. | .
*---* . *---* . *---* . *---* .
.............<.||||| .<............ .......<..||| .<...... .......<..|.| .<...... .<...| .
. +---------+|||+---------+ . . ||| . . | | . . | .
. | +----+|+----+ | . . +----+|+----+ . . +----+ +----+ . . | .
. | | | | | . . | | | . . | | . . | .
. *---* *---* *---* *---* *---* . . *---* *---* *---* . . *---* *---* . . *---* .
.>.|...|.|...|.|...|.|...|.|...|.>. .>.|...|.|...|.|...|.>. .>.|...|.......|...|.>. .>.|...|.>.
*---* *---* *---* *---* *---* *---* *---* *---* *---* *---* *---*
Se usa el metodo Enumeration postorderEnumeration().
Visito el Nodo Rama despues de haber visitado sus hijos.
*---*
comienzo ..........>>...| ..|...>>......... terminacion
.*---*
............................... |.|..................................
. +----------------------------+ +----------------------------+ .
. | | .
.*---* *---* .
.| ..|.>................................................... | ..|.>.
.*---* . *---*
...............................| |.|.<............................... . |...<.
. +---------------------------+ | +---------------------------+ . . | .
. | | | . . | .
.*---* *---* *---* . . *---* .
.| ..|.>.......................| ..|.>.......................| ..|.>. . | ..|.>.
.*---* .*---* .*---* . *---*
...............|||||.<............. ......... |||..<....... ......... |.|..<....... . |
. +---------+|||+---------+ . . ||| . . | | . . |...<.
. | +----+|+----+ | . . +----+|+----+ . . +----+ +----+ . . | .
. | | | | | . . | | | . . | | . . | .
. *---* *---* *---* *---* *---* . . *---* *---* *---* . . *---* *---* . . *---* .
.>.|...|.|...|.|...|.|...|.|...|.>. .>.|...|.|...|.|...|.>. .>.|...|.......|...|.>. .>.|...|.>.
*---* *---* *---* *---* *---* *---* *---* *---* *---* *---* *---*
Navegacion del Arbol 1, segun representacion por filas :
Breadth First Depth First Preorder Traversal Postorder Traversal
. . . .
V V V V
*---* *---*. *---* *---*.
| ..|....... | |.......... | ..|....... | |..........
*---* . *---* . *---* . *---* .
V V V V
*---* *---*. *---* *---*.
| . | ...| |. | ..|........ .|.. |.
*---* . .*---*. *---* . .*---*.
. ....... . . ........ . . . ........
. . V . . V V . . V
. . *---* . . *---* *---* . . *---*
. . | . | . . | . | | . | . . | . |
. . *---* . . *---* *---* . . *---*
. . . . . . . . . .
. . V . . V V . . V
. . *---* . . *---* *---* . . *---*
. . | . | . ...........|.. | | . | . ........|.. |
. . *---* . *---* *---* . *---*
. . . ...... ........... ....
V . . V V V
*---* . . *---* *---* *---*
| . | . . | . | | . | | . |
*---* . . *---* *---* *---*
. . . .... . ....
V . . . V .
*---* . . *---*. *---* *---*.
| . | . . ...| |. | ..|........ .|.. |.
*---* . . . .*---*. *---* . .*---*.
. . . . . ........ . . . ........
..... V . . V V . . V
*---* . . *---* *---* . . *---*
| . | . ...........|.. | | . | . ........|.. |
*---* . *---* *---* . *---*
. . . .
V V V V
Arbol 1 Arbol 1 Arbol 1 Arbol 1
Aclaraciones sobre la navegacion entre hermanos :
Existen las siguientes formas secundarias o parciales, muy útiles en ciertos
aspectos :
DefaultMutableTreeNode()
DefaultMutableTreeNode(Object userObject)
DefaultMutableTreeNode(Object userObject, boolean allowsChildren)
boolean isLeaf()
boolean isRoot()
boolean getAllowsChildren()
void setAllowsChildren(boolean allows)
int getLevel()
int getDepth()
Object getUserObject()
void setUserObject(Object userObject)
String toString()
Object clone()
TreeNode getParent()
TreeNode getRoot()
boolean isNodeAncestor(TreeNode anotherNode)
void setParent(MutableTreeNode newParent)
void removeFromParent()
TreeNode getSharedAncestor(DefaultMutableTreeNode aNode)
TreeNode[] getPath()
protected TreeNode[] getPathToRoot(TreeNode aNode, int depth)
Object[] getUserObjectPath()
Enumeration pathFromAncestorEnumeration(TreeNode ancestor)
TreeNode getFirstChild()
TreeNode getChildAfter(TreeNode aChild)
TreeNode getChildBefore(TreeNode aChild)
TreeNode getLastChild()
TreeNode getChildAt(int index)
int getIndex(TreeNode aChild)
int getChildCount()
int getLeafCount()
boolean isNodeChild(TreeNode aNode)
boolean isNodeDescendant(DefaultMutableTreeNode anotherNode)
Enumeration children()
Enumeration breadthFirstEnumeration()
Enumeration depthFirstEnumeration()
Enumeration postorderEnumeration()
Enumeration preorderEnumeration()
void add(MutableTreeNode newChild)
void insert(MutableTreeNode newChild, int childIndex)
void remove(int childIndex)
void remove(MutableTreeNode aChild)
void removeAllChildren()
int getSiblingCount()
DefaultMutableTreeNode getNextNode()
DefaultMutableTreeNode getPreviousNode()
DefaultMutableTreeNode getNextSibling()
DefaultMutableTreeNode getPreviousSibling()
DefaultMutableTreeNode getFirstLeaf()
DefaultMutableTreeNode getNextLeaf()
DefaultMutableTreeNode getPreviousLeaf()
DefaultMutableTreeNode getLastLeaf()
boolean isNodeRelated(DefaultMutableTreeNode aNode)
boolean isNodeSibling(TreeNode anotherNode)
protected TreePath()
TreePath(Object singlePath)
TreePath(Object[] path)
protected TreePath(Object[] path, int length)
protected TreePath(TreePath parent, Object lastElement)
boolean equals(Object o)
Object getLastPathComponent()
TreePath getParentPath()
Object[] getPath()
Object getPathComponent(int element)
int getPathCount()
int hashCode()
boolean isDescendant(TreePath aTreePath)
TreePath pathByAddingChild(Object child)
String toString()
En el siguiente programa ejemplo crearemos, representaremos y operaremos sobre el Arbol 8.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.util.*;
public class SimpleTree
{ public static void main(String[] args)
{ JFrame frame = new SimpleTreeFrame();
frame.show();
}
}
class SimpleTreeFrame extends JFrame
{
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Mundo");
DefaultMutableTreeNode arge = new DefaultMutableTreeNode("Argentina");
DefaultMutableTreeNode sant = new DefaultMutableTreeNode("Santa Fe");
DefaultMutableTreeNode rafa = new DefaultMutableTreeNode("Rafaela");
DefaultMutableTreeNode rosa = new DefaultMutableTreeNode("Rosario");
DefaultMutableTreeNode safe = new DefaultMutableTreeNode("Santa Fe");
DefaultMutableTreeNode vena = new DefaultMutableTreeNode("Venado Tuerto");
DefaultMutableTreeNode vill = new DefaultMutableTreeNode("Villa Constitucion");
DefaultMutableTreeNode cord = new DefaultMutableTreeNode("Cordoba");
DefaultMutableTreeNode codo = new DefaultMutableTreeNode("Cordoba");
DefaultMutableTreeNode cbro = new DefaultMutableTreeNode("Cura Brochero");
DefaultMutableTreeNode rcua = new DefaultMutableTreeNode("Rio Cuarto");
DefaultMutableTreeNode chac = new DefaultMutableTreeNode("Chaco");
DefaultMutableTreeNode resi = new DefaultMutableTreeNode("Resistencia");
DefaultMutableTreeNode vang = new DefaultMutableTreeNode("Villa Angela");
DefaultMutableTreeNode chil = new DefaultMutableTreeNode("Chile");
DefaultMutableTreeNode regi = new DefaultMutableTreeNode("Region Metropolitana");
DefaultMutableTreeNode schi = new DefaultMutableTreeNode("Santiago de Chile");
public SimpleTreeFrame()
{ setTitle("SimpleTree");
setSize(300, 200);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} );
root.add(arge); // Enlazado de nodos
arge.add(sant); // Enlazado de nodos
sant.add(rafa); // Enlazado de nodos
sant.add(rosa); // Enlazado de nodos
sant.add(safe); // Enlazado de nodos
sant.add(vena); // Enlazado de nodos
sant.add(vill); // Enlazado de nodos
arge.add(cord); // Enlazado de nodos
cord.add(codo); // Enlazado de nodos
cord.add(cbro); // Enlazado de nodos
cord.add(rcua); // Enlazado de nodos
arge.add(chac); // Enlazado de nodos
chac.add(resi); // Enlazado de nodos
chac.add(vang); // Enlazado de nodos
root.add(chil); // Enlazado de nodos
chil.add(regi); // Enlazado de nodos
regi.add(schi); // Enlazado de nodos
JTree tree = new JTree(root);
Container contentPane = getContentPane();
contentPane.add(new JScrollPane(tree));
Enumeration hijos = sant.children(); // Enumeracion de hijos
while ( hijos.hasMoreElements() ) // Enumeracion de hijos
{ // Enumeracion de hijos
System.err.println("Hijos de Santa Fe : "+hijos.nextElement()); // Enumeracion de hijos
} // Enumeracion de hijos
boolean hoja = vena.isLeaf(); // Consulta Hoja
System.err.println("Es Venado Tuerto hoja : "+hoja); // Consulta Hoja
Enumeration breadth = root.breadthFirstEnumeration(); // Enumeracion Nodos
while ( breadth.hasMoreElements() ) // Enumeracion Nodos
{ // Enumeracion Nodos
System.err.println("Breadth First : "+breadth.nextElement()); // Enumeracion Nodos
} // Enumeracion Nodos
Enumeration depth = root.depthFirstEnumeration(); // Enumeracion Nodos
while ( depth.hasMoreElements() ) // Enumeracion Nodos
{ // Enumeracion Nodos
System.err.println("Depth First : "+depth.nextElement()); // Enumeracion Nodos
} // Enumeracion Nodos
Enumeration preorder = root.preorderEnumeration(); // Enumeracion Nodos
while ( preorder.hasMoreElements() ) // Enumeracion Nodos
{ // Enumeracion Nodos
System.err.println("Pre Order : "+preorder.nextElement()); // Enumeracion Nodos
} // Enumeracion Nodos
Enumeration postorder = root.postorderEnumeration(); // Enumeracion Nodos
while ( postorder.hasMoreElements() ) // Enumeracion Nodos
{ // Enumeracion Nodos
System.err.println("Post Order : "+postorder.nextElement()); // Enumeracion Nodos
} // Enumeracion Nodos
}
}
Siendo su output, en lo que a las enumeraciones se refiere :
Breadth First : Mundo Depth First : Rafaela Pre Order : Mundo Post Order : Rafaela
Breadth First : Argentina Depth First : Rosario Pre Order : Argentina Post Order : Rosario
Breadth First : Chile Depth First : Santa Fe Pre Order : Santa Fe Post Order : Santa Fe
Breadth First : Santa Fe Depth First : Venado Tuerto Pre Order : Rafaela Post Order : Venado Tuerto
Breadth First : Cordoba Depth First : Villa Constitucion Pre Order : Rosario Post Order : Villa Constitucion
Breadth First : Chaco Depth First : Santa Fe Pre Order : Santa Fe Post Order : Santa Fe
Breadth First : Region Metropolitana Depth First : Cordoba Pre Order : Venado Tuerto Post Order : Cordoba
Breadth First : Rafaela Depth First : Cura Brochero Pre Order : Villa Constitucion Post Order : Cura Brochero
Breadth First : Rosario Depth First : Rio Cuarto Pre Order : Cordoba Post Order : Rio Cuarto
Breadth First : Santa Fe Depth First : Cordoba Pre Order : Cordoba Post Order : Cordoba
Breadth First : Venado Tuerto Depth First : Resistencia Pre Order : Cura Brochero Post Order : Resistencia
Breadth First : Villa Constitucion Depth First : Villa Angela Pre Order : Rio Cuarto Post Order : Villa Angela
Breadth First : Cordoba Depth First : Chaco Pre Order : Chaco Post Order : Chaco
Breadth First : Cura Brochero Depth First : Argentina Pre Order : Resistencia Post Order : Argentina
Breadth First : Rio Cuarto Depth First : Santiago de Chile Pre Order : Villa Angela Post Order : Santiago de Chile
Breadth First : Resistencia Depth First : Region Metropolitana Pre Order : Chile Post Order : Region Metropolitana
Breadth First : Villa Angela Depth First : Chile Pre Order : Region Metropolitana Post Order : Chile
Breadth First : Santiago de Chile Depth First : Mundo Pre Order : Santiago de Chile Post Order : Mundo