Ejemplo n.º 1
0
 public void PreorderTraversal <T>(List <T> nodes)
 {
     if (root != null)
     {
         root.PreOrderTraversal(nodes);
     }
 }
Ejemplo n.º 2
0
        //Root->Left->Right Nodes recursively of each subtree
        public void PreOrderTraversal <T>(List <T> nodes)
        {
            //First we print the root node
            Debug.Log(data + " id: " + nodeID);
            nodes.Add((T)data);
            //Then go to left child its children will be null so we print its data
            if (leftNode != null)
            {
                leftNode.PreOrderTraversal(nodes);
            }

            //Then we go to the right node which will print itself as both its children are null
            if (rightNode != null)
            {
                rightNode.PreOrderTraversal(nodes);
            }
        }