Esempio n. 1
0
 // add value in the root and add children of the root
 public TreeFindOccurrenceNumber(int value, params TreeFindOccurrenceNumber[] children)
 {
     this.root = new TreeChild(value);
     foreach (TreeFindOccurrenceNumber child in children)
     {
         this.root.AddChild(child.root);
     }
 }
Esempio n. 2
0
 public void PrintDFS(TreeChild root, string space)
 {
     Console.WriteLine(space + root.Value);
     for (int i = 0; i < root.Size; i++)
     {
         //get the children of the node
         PrintDFS(root.getChild(i), space + " ");
     }
 }
Esempio n. 3
0
 /// <summary> part 5:
 /// print the vertices of a tree having leave successors
 /// </summary>
 public void PrintVertices(TreeChild node)
 {
     if (node.childNode.Count != 0 && node != this.root)
     {
         Console.Write(node.Value + " ");
     }
     for (int i = 0; i < node.Size; i++)
     {
         PrintVertices(node.getChild(i));
     }
 }
Esempio n. 4
0
 private void ShowNodeOf(int k, TreeChild node)
 {
     if (k == node.childNode.Count)
     {
         Console.Write(node.Value + " ");
     }
     for (int i = 0; i < node.Size; i++)
     {
         ShowNodeOf(k, node.getChild(i));
     }
 }
Esempio n. 5
0
 private int NumberOfInternalNodes(TreeChild node)
 {
     if (node.childNode.Count != 0 && node != this.root)
     {
         numberOfVertices++;
     }
     for (int i = 0; i < node.Size; i++)
     {
         NumberOfInternalNodes(node.getChild(i));
     }
     return(numberOfVertices);
 }
Esempio n. 6
0
 private int NumberOfLeaf(TreeChild node)
 {
     if (node.childNode.Count == 0)
     {
         numberOfLeaf++;
     }
     for (int i = 0; i < node.Size; i++)
     {
         NumberOfLeaf(node.getChild(i));
     }
     return(numberOfLeaf);
 }
Esempio n. 7
0
 /// <summary>
 /// Find the given value in a tree
 /// </summary>
 /// <param name="value">the given value</param>
 /// <param name="node">root of the tree</param>
 private void NumberOfOccurrence(int value, TreeChild node)
 {
     if (value == node.Value)
     {
         count++;
     }
     // to traverse all the node child
     for (int i = 0; i < node.Size; i++)
     {
         NumberOfOccurrence(value, node.getChild(i));
     }
 }
Esempio n. 8
0
 private void SumOfNodes(TreeChild node)
 {
     if (node.childNode.Count != 0 && node != this.root)
     {
         numberOfVertices += node.Value;
     }
     if (node.childNode.Count == 0)
     {
         numberOfLeaf += node.Value;
     }
     for (int i = 0; i < node.Size; i++)
     {
         SumOfNodes(node.getChild(i));
     }
 }
Esempio n. 9
0
 // add value in the root
 public TreeFindOccurrenceNumber(int value)
 {
     this.root = new TreeChild(value);
 }
Esempio n. 10
0
 public void AddChild(TreeChild node)
 {
     this.childNode.Add(node);
 }