当前位置: 首页>>代码示例>>C#>>正文


C# BinaryTreeNode类代码示例

本文整理汇总了C#中BinaryTreeNode的典型用法代码示例。如果您正苦于以下问题:C# BinaryTreeNode类的具体用法?C# BinaryTreeNode怎么用?C# BinaryTreeNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BinaryTreeNode类属于命名空间,在下文中一共展示了BinaryTreeNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsSubTree

 public static bool IsSubTree(BinaryTreeNode<int> smallerTreeRoot, BinaryTreeNode<int> largerTreeRoot)
 {
     if (smallerTreeRoot == null) return true;
     else if (largerTreeRoot == null) return false;
     if (AreIdentical(smallerTreeRoot, largerTreeRoot)) return true;
     return IsSubTree(smallerTreeRoot, largerTreeRoot.Left) || IsSubTree(smallerTreeRoot, largerTreeRoot.Right);
 }
开发者ID:bonniepan02,项目名称:Practice,代码行数:7,代码来源:TreeStructurePropertyHelper.cs

示例2: BruteForce

        private static BinaryTreeNode<int> BruteForce(BinaryTreeNode<int> root, int a, int b)
        {
            BinaryTreeNode<int> n1 = BinarySearchTree.Find(root, a);
            BinaryTreeNode<int> n2 = BinarySearchTree.Find(root, b);

            int d1 = ComputeLCA.Depth(n1);
            int d2 = ComputeLCA.Depth(n2);

            while (d1 > d2)
            {
                n1 = n1.Parent;
                d1--;
            }

            while (d2 > d1)
            {
                n2 = n2.Parent;
                d2--;
            }

            while (!object.Equals(n1, n2))
            {
                n1 = n1.Parent;
                n2 = n2.Parent;
            }

            return n1;
        }
开发者ID:mmoroney,项目名称:Algorithms,代码行数:28,代码来源:ComputeLCA.cs

示例3: FindLowestCommonAncestorInBST

 public static BinaryTreeNode<int> FindLowestCommonAncestorInBST(BinaryTreeNode<int> root, BinaryTreeNode<int> node1, BinaryTreeNode<int> node2)
 {
     if (root == null || node1 == null || node2 == null) return null;
     if (root.Value > Max(node1.Value, node2.Value)) return FindLowestCommonAncestorInBST(root.Left, node1, node2);
     if (root.Value < Min(node1.Value, node2.Value)) return FindLowestCommonAncestorInBST(root.Right, node1, node2);
     return root;
 }
开发者ID:bonniepan02,项目名称:Practice,代码行数:7,代码来源:TreeStructurePropertyHelper.cs

示例4: testNotInTree

        public void testNotInTree()
        {
            BinaryTreeNode<Int32> root = new BinaryTreeNode<Int32>(2);
            root.insert(5);
            root.insert(1);
            root.insert(16);
            bool exceptionCaught_v1 = false;
            bool exceptionCaught_v2 = false;
            bool exceptionCaught_v3 = false;

            #pragma warning disable 168
            try {
                Assert.AreEqual(eu.sig.training.ch03.binarytree.v1.BinaryTreeSearch.calculateDepth(root, 17), 0);
            } catch (TreeException e) {
                exceptionCaught_v1 = true;
            }
            try {
                Assert.AreEqual(eu.sig.training.ch03.binarytree.v2.BinaryTreeSearch
                    .calculateDepth(root, 17), 0);
            } catch (TreeException e) {
                exceptionCaught_v2 = true;
            }
            try {
                Assert.AreEqual(eu.sig.training.ch03.binarytree.v3.BinaryTreeSearch
                    .calculateDepth(root, 17), 0);
            } catch (TreeException e) {
                exceptionCaught_v3 = true;
            }
            Assert.IsTrue(exceptionCaught_v1);
            Assert.IsTrue(exceptionCaught_v2);
            Assert.IsTrue(exceptionCaught_v3);
            #pragma warning restore 168
        }
开发者ID:makyr90,项目名称:building_maintainable_software,代码行数:33,代码来源:BinaryTreeSearchTest.cs

示例5: ShouldCorrectlyCreateRootNode

        public void ShouldCorrectlyCreateRootNode()
        {
            var root = new BinaryTreeNode<int>(null);

            Assert.AreEqual(null, root.Parent);
            Assert.IsTrue(root.IsRoot);
        }
开发者ID:kament,项目名称:SDA_SU_CollectionsForDummies,代码行数:7,代码来源:BinaryTreeNodeTests.cs

示例6: getLevelLinkedList

        public static System.Collections.Generic.Dictionary<System.Int16, System.Collections.Generic.List<BinaryTreeNode>> getLevelLinkedList(BinaryTreeNode head)
        {
            System.Collections.Generic.Dictionary<System.Int16, System.Collections.Generic.List<BinaryTreeNode>> result
                = new System.Collections.Generic.Dictionary<System.Int16, System.Collections.Generic.List<BinaryTreeNode>>();
            short level = 0;
            System.Collections.Generic.List<BinaryTreeNode> list = new System.Collections.Generic.List<BinaryTreeNode>();
            list.Add(head);
            result.Add(level, list);

            while (true)
            {
                System.Collections.Generic.List<BinaryTreeNode> list_loop = result[level];
                list = new System.Collections.Generic.List<BinaryTreeNode>();
                result.Add(++level, list);
                foreach (BinaryTreeNode btn in list_loop)
                {
                    if (btn.LeftNode != null)
                    {
                        list.Add(btn.LeftNode);
                    }
                    if (btn.RightNode != null)
                    {
                        list.Add(btn.RightNode);
                    }
                }
                if (list.Count == 0)
                {
                    break;
                }
            }
            return result;
        }
开发者ID:Sanqiang,项目名称:Algorithm-Win,代码行数:32,代码来源:CC4_4.cs

示例7: findSumExDepth

        public static void findSumExDepth(BinaryTreeNode root, double threshold, int level = 0,
            System.Collections.Generic.List<BinaryTreeNode> list = null)
        {
            if (list == null)
            {
                list = new System.Collections.Generic.List<BinaryTreeNode>();
                list.Add(root);
                if (root.Data == threshold)
                {
                    printPath(list);
                }
            }
            else
            {
                list.Add(root);
                double tmp = threshold;
                for (int i = level; i >= 0; i--)
                {
                    tmp -= list[i].Data;
                    if (tmp == 0)
                    {
                        printPath(list, i);
                    }
                }
            }

            if (root.LeftNode != null)
            {
                findSumExDepth(root.LeftNode, threshold, level + 1, clone(list));
            }
            if (root.RightNode != null)
            {
                findSumExDepth(root.RightNode, threshold, level + 1, clone(list));
            }
        }
开发者ID:Sanqiang,项目名称:Algorithm-Win,代码行数:35,代码来源:CC4_8.cs

示例8: NewNodeHasParent

 public void NewNodeHasParent()
 {
     BinaryTreeNode<int> node = new BinaryTreeNode<int>(1);
     BinaryTreeNode<int> node2 = new BinaryTreeNode<int>(2);
     node.Left = node2;
     Assert.AreEqual(node2.Parent, node);
 }
开发者ID:sarah-story,项目名称:binary-tree,代码行数:7,代码来源:BinaryTreeNodeTest.cs

示例9: CanGetParent

 public void CanGetParent()
 {
     BinaryTreeNode<int> left = new BinaryTreeNode<int>(2);
     BinaryTreeNode<int> right = new BinaryTreeNode<int>(3);
     BinaryTreeNode<int> node = new BinaryTreeNode<int>(1, left, right);
     Assert.AreEqual(node.Left.Parent, node);
 }
开发者ID:sarah-story,项目名称:binary-tree,代码行数:7,代码来源:BinaryTreeNodeTest.cs

示例10: UnknowContact

        private BinaryTreeNode<Script> UnknowContact()
        {
            var root = new BinaryTreeNode<Script>(new Script
            {
                Question =
                    "Could you please tell me the name of the person who is responsible for the cleaning of your premises?",
                Actions = new Collection<ScriptAction>
                {
                    new UpdateContactName()
                },
            });

            root.Right = KnownContact();
            root.Left = new BinaryTreeNode<Script>(new Script
            {
                Question =
                    "We would like to send the relevant person some information on our services that they could find useful in the future. I do not " +
                    "need to speak to the person. Could you just tell me their name",
                Actions = new Collection<ScriptAction>
                {
                    new UpdateContactName()
                }
            });

            root.Left.Left = End(false);
            root.Left.Right = End(true);

            return root;
        }
开发者ID:changLiuUNSW,项目名称:BDSystem,代码行数:29,代码来源:OprScriptCreator.cs

示例11: VisitNode

        ////Algo
        //      5
        //   3     7
        // 1   4  6  8

        int VisitNode(BinaryTreeNode<int> treeNode)
        {
            int leftVal = 0, rightVal = 0;
            if(treeNode.Left == null)
            {
                leftVal = -1;
            }
            else
            {
                leftVal = VisitNode(treeNode.Left);
            }
            if(treeNode.Right == null)
            {
                rightVal = -1;
            }
            else
            {
                rightVal = VisitNode(treeNode.Right);
            }

            if(Math.Abs(leftVal - rightVal) > 1)
            {
                Console.WriteLine("Tree is not balanced");
            }

            return (leftVal > rightVal ? leftVal : rightVal) + 1;
        }
开发者ID:suhasaraos,项目名称:Test,代码行数:32,代码来源:CheckTreeIsBalanced.cs

示例12: FindNode

 public static BinaryTreeNode<int> FindNode(BinaryTreeNode<int> node, int searchValue)
 {
     if (node != null)
     {
         if (node.Value == searchValue)
         {
             CalcStack.Push(node.InitialValue.ToString());
             return node;
         }
         else
         {
             var right = FindNode(node.Right, searchValue);
             if (right != null)
             {
                 CalcStack.Push("*");
                 CalcStack.Push(node.InitialValue.ToString());
                 return right;
             }
             else
             {
                 var left = FindNode(node.Left, searchValue);
                 if (left != null)
                 {
                     CalcStack.Push("+");
                     CalcStack.Push(node.InitialValue.ToString());
                     return left;
                 }
             }
         }
     }
     return null;
 }
开发者ID:Raylehnhoff,项目名称:CSCareerQuestionsSearch,代码行数:32,代码来源:Program.cs

示例13: Must_construct_root_node

            public void Must_construct_root_node()
            {
                var systemUnderTest = new BinaryTreeNode();

                Assert.That(systemUnderTest.Ancestor, Is.Null);
                Assert.That(systemUnderTest.IsRoot, Is.True);
            }
开发者ID:nathan-alden,项目名称:junior-common,代码行数:7,代码来源:BinaryTreeNodeTester.cs

示例14: inorderSucc

 public static BinaryTreeNode inorderSucc(BinaryTreeNode orignal)
 {
     if (orignal.ParentNode == null && orignal.RightNode != null)
     {
         BinaryTreeNode btn = orignal.RightNode;
         while (btn != null)
         {
             if (btn.LeftNode != null)
             {
                 return btn.LeftNode;
             }
             btn = btn.RightNode;
         }
     }
     else
     {
         BinaryTreeNode btn = orignal;
         while (btn.ParentNode != null)
         {
             if (btn.ParentNode.LeftNode == btn)
             {
                 return btn.ParentNode;
             }
             btn = btn.ParentNode;
         }
         return btn;
     }
     return null;
 }
开发者ID:Sanqiang,项目名称:Algorithm-Win,代码行数:29,代码来源:CC4_5.cs

示例15: Must_have_no_descendants

            public void Must_have_no_descendants()
            {
                var systemUnderTest = new BinaryTreeNode();

                Assert.That(systemUnderTest.LeftDescendant, Is.Null);
                Assert.That(systemUnderTest.RightDescendant, Is.Null);
            }
开发者ID:nathan-alden,项目名称:junior-common,代码行数:7,代码来源:BinaryTreeNodeTester.cs


注:本文中的BinaryTreeNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。