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 + " "); } }
/// <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)); } }
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)); } }
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); }
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); }
/// <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)); } }
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)); } }