public BinaryTree(T value , IAbstractBinaryTree <T> leftChild , IAbstractBinaryTree <T> rightChild) { this.Value = value; this.LeftChild = leftChild; this.RightChild = rightChild; }
public void Setup() { this._binaryTree = new BinaryTree <int>(7, new BinaryTree <int>(21, null, null), new BinaryTree <int>(14, new BinaryTree <int>(23, null, null), new BinaryTree <int>(6, null, new BinaryTree <int>(13, null, null)))); }
private void InOrderSearch(List <IAbstractBinaryTree <T> > list, IAbstractBinaryTree <T> tree) { if (tree != null) { this.InOrderSearch(list, tree.LeftChild); list.Add(tree); this.InOrderSearch(list, tree.RightChild); } }
private void PostOrderWithDFS(IAbstractBinaryTree <T> currentNode, List <IAbstractBinaryTree <T> > result) { if (currentNode != null) { this.PostOrderWithDFS(currentNode.LeftChild, result); this.PostOrderWithDFS(currentNode.RightChild, result); result.Add(currentNode); } }
public void InitializeBinaryTree() { this._tree = new BinaryTree <int>(17, new BinaryTree <int>(9, new BinaryTree <int>(3, null, null), new BinaryTree <int>(11, null, null)), new BinaryTree <int>(25, new BinaryTree <int>(20, null, null), new BinaryTree <int>(31, null, null)) ); }
private void PreOrder(IAbstractBinaryTree <T> node, List <IAbstractBinaryTree <T> > result) { if (node != null) { result.Add(node); PreOrder(node.LeftChild, result); PreOrder(node.RightChild, result); } }
private void GetRight(IAbstractBinaryTree <T> node, List <T> result) { if (node == null) { return; } result.Add(node.Value); GetRight(node.RightChild, result); }
private void AsIndentedPreOrderWithDFS(IAbstractBinaryTree <T> currentNode, int indent, StringBuilder sb) { if (currentNode != null) { sb.Append(new String(' ', indent) + currentNode.Value + Environment.NewLine); indent += 2; this.AsIndentedPreOrderWithDFS(currentNode.LeftChild, indent, sb); this.AsIndentedPreOrderWithDFS(currentNode.RightChild, indent, sb); } }
private void AddInOrder(IAbstractBinaryTree <T> node, Action <T> action) { if (node == null) { return; } this.AddInOrder(node.LeftChild, action); action(node.Value); this.AddInOrder(node.RightChild, action); }
private void AddInOrder(IAbstractBinaryTree <T> node, List <IAbstractBinaryTree <T> > result) { if (node == null) { return; } this.AddInOrder(node.LeftChild, result); result.Add(node); this.AddInOrder(node.RightChild, result); }
private void ForEachInOrderWithDFS(IAbstractBinaryTree <T> currentNode, Action <T> action) { if (currentNode != null) { this.ForEachInOrderWithDFS(currentNode.LeftChild, action); action.Invoke(currentNode.Value); this.ForEachInOrderWithDFS(currentNode.RightChild, action); } }
private void AsIndentedPreOrderDfs(IAbstractBinaryTree <T> current, int indent, StringBuilder sb) { sb.AppendLine($"{new string(' ', indent)}{current.Value}"); if (current.LeftChild != null) { this.AsIndentedPreOrderDfs(current.LeftChild, indent + 2, sb); } if (current.RightChild != null) { this.AsIndentedPreOrderDfs(current.RightChild, indent + 2, sb); } }
private void IndentPreOrder(int indent, IAbstractBinaryTree <T> node, StringBuilder result) { if (node == null) { return; } result.AppendLine(new string(' ', indent) + node.Value); this.IndentPreOrder(indent + 2, node.LeftChild, result); this.IndentPreOrder(indent + 2, node.RightChild, result); }
private void AsIndentedPreOrderDfs(IAbstractBinaryTree <T> binaryTree, int indent, StringBuilder sb) { sb.AppendLine(new string(' ', indent) + binaryTree.Value); if (binaryTree.LeftChild != null) { this.AsIndentedPreOrderDfs(binaryTree.LeftChild, indent + 2, sb); } if (binaryTree.RightChild != null) { this.AsIndentedPreOrderDfs(binaryTree.RightChild, indent + 2, sb); } }
// private Methods private void PreOrderIndentDfs(IAbstractBinaryTree <T> tree, StringBuilder result, int indent) { result.AppendLine(new string(' ', indent) + tree.Value); if (tree.LeftChild != null) { this.PreOrderIndentDfs(tree.LeftChild, result, indent + 2); } if (tree.RightChild != null) { this.PreOrderIndentDfs(tree.RightChild, result, indent + 2); } }
private void AsIndentedPreOrder(IAbstractBinaryTree <T> node, StringBuilder result, int indent) { result.AppendLine($"{new string(' ', indent)}{node.Value}"); if (node.LeftChild != null) { AsIndentedPreOrder(node.LeftChild, result, indent + 2); } if (node.RightChild != null) { AsIndentedPreOrder(node.RightChild, result, indent + 2); } }
private void InOrderDfsAction(IAbstractBinaryTree <T> binaryTree, Action <T> action) { if (binaryTree.LeftChild != null) { this.InOrderDfsAction(binaryTree.LeftChild, action); } action.Invoke(binaryTree.Value); if (binaryTree.RightChild != null) { this.InOrderDfsAction(binaryTree.RightChild, action); } }
private void InOrderDfs(IAbstractBinaryTree <T> binaryTree, List <IAbstractBinaryTree <T> > list) { if (binaryTree.LeftChild != null) { this.InOrderDfs(binaryTree.LeftChild, list); } list.Add(binaryTree); if (binaryTree.RightChild != null) { this.InOrderDfs(binaryTree.RightChild, list); } }
private void AsIndentedPreOrderDfsTraversal(IAbstractBinaryTree <T> subtree, int indent, StringBuilder result) { result.AppendLine($"{new String(' ', indent)}{subtree.Value}"); if (subtree.LeftChild != null) { this.AsIndentedPreOrderDfsTraversal(subtree.LeftChild, indent + 2, result); } if (subtree.RightChild != null) { this.AsIndentedPreOrderDfsTraversal(subtree.RightChild, indent + 2, result); } }
public string DFSPreorder(IAbstractBinaryTree <T> node, int indent) { string result = $"{new string(' ', indent)}{node.Value}\r\n"; if (node.LeftChild != null) { result += DFSPreorder(node.LeftChild, indent + 2); } if (node.RightChild != null) { result += DFSPreorder(node.RightChild, indent + 2); } return(result); }
public void Setup() { this._binaryTree = new BinaryTree <int>( 12, new BinaryTree <int>( 5, new BinaryTree <int>(1, null, null), new BinaryTree <int>(8, null, null) ), new BinaryTree <int>( 19, new BinaryTree <int>(16, null, null), new BinaryTree <int>(23, new BinaryTree <int>(21, null, null), new BinaryTree <int>(30, null, null) ) ) ); }
private List <IAbstractBinaryTree <T> > DFSInOrder(IAbstractBinaryTree <T> node, List <IAbstractBinaryTree <T> > result) { List <IAbstractBinaryTree <T> > list = new List <IAbstractBinaryTree <T> >(); if (node.LeftChild != null) { this.DFSInOrder(node.LeftChild, result); } result.Add(node); if (node.RightChild != null) { this.DFSInOrder(node.RightChild, result); } return(result); }