• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# BinaryTreeNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: findSum

 public static void findSum(BinaryTreeNode root, double threshold, double count = 0,
     System.Collections.Generic.List<BinaryTreeNode> list = null)
 {
     if (list == null)
     {
         list = new System.Collections.Generic.List<BinaryTreeNode>();
     }
     double Data = root.Data;
     count += Data;
     list.Add(root);
     if (count == threshold)
     {
         printPath(list);
     }
     if (root.LeftNode != null)
     {
         findSum(root.LeftNode, threshold, count, clone(list));
         findSum(root.LeftNode, threshold);
     }
     if (root.RightNode != null)
     {
         findSum(root.RightNode, threshold, count, clone(list));
         findSum(root.RightNode, threshold);
     }
 }
开发者ID:Sanqiang,项目名称:Algorithm-Win,代码行数:25,代码来源:CC4_8.cs


示例17: ShouldNotHaveChildNodesInitialy

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

            Assert.IsFalse(root.HasLeftChild);
            Assert.IsFalse(root.HasRightChild);
        }
开发者ID:kament,项目名称:SDA_SU_CollectionsForDummies,代码行数:7,代码来源:BinaryTreeNodeTests.cs


示例18: SatisfiesBSTTest

        public void SatisfiesBSTTest()
        {
            Func<BinaryTreeNode<int>, bool>[] functions = new Func<BinaryTreeNode<int>, bool>[]
            {
                SatisfiesBST.BruteForce,
                SatisfiesBST.Recursive,
                SatisfiesBST.InOrderTraversal,
                SatisfiesBST.Queue
            };

            for (int i = 0; i < 10; i++)
            {
                int[] data = ArrayUtilities.CreateRandomArray(10, 0, 20);

                BinaryTreeNode<int> root = new BinaryTreeNode<int>(data[0]);

                for(int j = 1; j < data.Length; j++)
                {
                    BinarySearchTree.Insert(root, data[j]);
                    Tests.TestFunctions(root, functions);
                }

                root = new BinaryTreeNode<int>(data[0]);

                for (int j = 1; j < data.Length; j++)
                {
                    BinaryTreeUtilities.AddRandomNode(root, data[j]);
                    Tests.TestFunctions(root, functions);
                }
            }
        }
开发者ID:mmoroney,项目名称:Algorithms,代码行数:31,代码来源:SatisfiesBST.cs


示例19: CalculateDepth

 // tag::calculateDepth[]
 public static int CalculateDepth(BinaryTreeNode<int> t, int n)
 {
     int depth = 0;
     if (t.Value == n)
     {
         return depth;
     }
     else
     {
         if (n < t.Value)
         {
             BinaryTreeNode<int> left = t.Left;
             if (left == null)
             {
                 throw new TreeException("Value not found in tree!");
             }
             else
             {
                 return 1 + CalculateDepth(left, n);
             }
         }
         else
         {
             BinaryTreeNode<int> right = t.Right;
             if (right == null)
             {
                 throw new TreeException("Value not found in tree!");
             }
             else
             {
                 return 1 + CalculateDepth(right, n);
             }
         }
     }
 }
开发者ID:oreillymedia,项目名称:building_maintainable_software,代码行数:36,代码来源:BinaryTreeSearch.cs


示例20: CalculateDepth

 // tag::calculateDepth[]
 public static int CalculateDepth(BinaryTreeNode<int> t, int n) {
     int depth = 0;
     if (t.Value == n) {
         return depth;
     } else {
         return TraverseByValue(t, n);
     }
 }
开发者ID:ishara,项目名称:building_maintainable_software,代码行数:9,代码来源:BinaryTreeSearch.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# BinaryWriter类代码示例发布时间:2022-05-24
下一篇:
C# BinaryTree类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap