コード例 #1
0
ファイル: BinaryTree.cs プロジェクト: PavelAndonov00/Softuni
 public BinaryTree(T value
                   , IAbstractBinaryTree <T> leftChild
                   , IAbstractBinaryTree <T> rightChild)
 {
     this.Value      = value;
     this.LeftChild  = leftChild;
     this.RightChild = rightChild;
 }
コード例 #2
0
ファイル: LCATests.cs プロジェクト: PavelAndonov00/Softuni
 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))));
 }
コード例 #3
0
 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);
     }
 }
コード例 #4
0
 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);
     }
 }
コード例 #5
0
 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))
                                       );
 }
コード例 #6
0
ファイル: BinaryTree.cs プロジェクト: VenziVi/SoftUni
 private void PreOrder(IAbstractBinaryTree <T> node, List <IAbstractBinaryTree <T> > result)
 {
     if (node != null)
     {
         result.Add(node);
         PreOrder(node.LeftChild, result);
         PreOrder(node.RightChild, result);
     }
 }
コード例 #7
0
        private void GetRight(IAbstractBinaryTree <T> node, List <T> result)
        {
            if (node == null)
            {
                return;
            }

            result.Add(node.Value);
            GetRight(node.RightChild, result);
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
     }
 }
コード例 #13
0
        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);
        }
コード例 #14
0
ファイル: BinaryTree.cs プロジェクト: PavelAndonov00/Softuni
        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);
            }
        }
コード例 #15
0
        // 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);
            }
        }
コード例 #16
0
ファイル: BinaryTree.cs プロジェクト: VenziVi/SoftUni
        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);
            }
        }
コード例 #17
0
        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);
            }
        }
コード例 #18
0
        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);
            }
        }
コード例 #19
0
        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);
            }
        }
コード例 #20
0
ファイル: BinaryTree.cs プロジェクト: ferricode/SoftUni
        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);
        }
コード例 #21
0
 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)
                                  )
             )
         );
 }
コード例 #22
0
ファイル: BinaryTree.cs プロジェクト: ferricode/SoftUni
        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);
        }