Beispiel #1
0
 private void PushChildren(Stack<TreeNode> stack, TreeNode node)
 {
     List<TreeNode> children = node.Children;
     for (int i = 0; i < children.Count; i++)
     {
         stack.Push(children[i]);
     }
 }
Beispiel #2
0
 public void Add(int parentValue, int numberValue)
 {
     TreeNode childNode = new TreeNode(numberValue);
     if (this.Root != null)
     {
         TreeNode parent = this.FindParentOf(parentValue);
         if(parent != null)
         {
             parent.Children.Add(childNode);
         }
         else
         {
             TreeNode newRoot = new TreeNode(parentValue);
             newRoot.Children.Add(this.Root);
             this.Root = newRoot;
         }
     }
     else
     {
         TreeNode parentNode = new TreeNode(parentValue);
         parentNode.Children.Add(childNode);
         this.Root = parentNode;
     }
 }