Esempio n. 1
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. 2
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. 3
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. 4
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. 5
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. 6
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. 7
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));
     }
 }