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


C# BinaryTree.Add方法代码示例

本文整理汇总了C#中BinaryTree.Add方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryTree.Add方法的具体用法?C# BinaryTree.Add怎么用?C# BinaryTree.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryTree的用法示例。


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

示例1: DeleteTest

 public void DeleteTest()
 {
     var tree = new BinaryTree<float>();
     tree.Add(4.21f);
     tree.Add(421);
     tree.Add(42);
     tree.Add(1);
     tree.Add(1000.500f);
     tree.Delete(4.21f);
     Assert.IsFalse(tree.Contains(4.21f));
     Assert.IsTrue(tree.Contains(421));
     Assert.IsTrue(tree.Contains(42));
     Assert.IsTrue(tree.Contains(1));
     tree.Delete(421);
     Assert.IsFalse(tree.Contains(421));
     Assert.IsTrue(tree.Contains(1));
     tree.Delete(1);
     Assert.IsFalse(tree.Contains(1));
     Assert.IsFalse(tree.Contains(421));
     Assert.IsTrue(tree.Contains(42));
     tree.Delete(42);
     Assert.IsFalse(tree.Contains(42));
     Assert.IsTrue(tree.Contains(1000.500f));
     tree.Delete(1000.500f);
     Assert.IsFalse(tree.Contains(1000.500f));
     Assert.IsTrue(tree.IsEmpty());
 }
开发者ID:Ivan-Nebogatikov,项目名称:Homeworks,代码行数:27,代码来源:BinaryTreeTests.cs

示例2: Interface

        public void Interface()
        {
            var rootBinaryTree = new BinaryTree<int>(5);

            var child1 = new BinaryTree<int>(2);
            var child2 = new BinaryTree<int>(3);

            rootBinaryTree.Add(child1);
            rootBinaryTree.Add(child2);

            var child4 = new BinaryTree<int>(9);
            var child5 = new BinaryTree<int>(12);
            var child6 = new BinaryTree<int>(13);

            child1.Add(child4);
            child1.Add(child5);
            child2.Add(child6);

            ITree<int> tree = rootBinaryTree;
            Assert.AreEqual(tree.FindNode(target => target == 2), child1);

            Assert.AreEqual(tree.FindNode(target => target == 9), child4);

            Assert.AreEqual(tree.FindNode(target => target == 13), child6
                );

            Assert.AreEqual(tree.FindNode(target => target == 57), null);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:28,代码来源:FindNode.cs

示例3: Simple

        public void Simple()
        {
            var binaryTree = new BinaryTree<int>(5);

            Assert.AreEqual(binaryTree.Count, 0);
            Assert.AreEqual(binaryTree.Degree, 0);
            Assert.AreEqual(binaryTree.Data, 5);

            binaryTree.Add(3);

            Assert.AreEqual(binaryTree.Count, 1);
            Assert.AreEqual(binaryTree.Degree, 1);
            Assert.AreEqual(binaryTree.Data, 5);

            Assert.AreEqual(binaryTree.Left.Data, 3);
            Assert.IsNull(binaryTree.Right);

            binaryTree.Add(4);

            Assert.AreEqual(binaryTree.Count, 2);
            Assert.AreEqual(binaryTree.Degree, 2);
            Assert.AreEqual(binaryTree.Data, 5);

            Assert.AreEqual(binaryTree.Left.Data, 3);
            Assert.AreEqual(binaryTree.Right.Data, 4);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:26,代码来源:Add.cs

示例4: BeginTestMethod

 public void BeginTestMethod()
 {
     target = new BinaryTree<String>();
     target.Add(3, "three");
     target.Add(2, "two");
     target.Add(7, "seven");
 }
开发者ID:hirotk,项目名称:Algorithm,代码行数:7,代码来源:BinarySearchTreeTest.cs

示例5: Simple

        public void Simple()
        {
            var binaryTree = new BinaryTree<int>(5);

            var child1 = new BinaryTree<int>(2);
            var child2 = new BinaryTree<int>(3);

            binaryTree.Add(child1);
            binaryTree.Add(child2);

            var child4 = new BinaryTree<int>(9);
            var child5 = new BinaryTree<int>(12);
            var child6 = new BinaryTree<int>(13);

            child1.Add(child4);
            child1.Add(child5);
            child2.Add(child6);

            Assert.AreEqual(binaryTree.FindNode(target => target == 2), child1);

            Assert.AreEqual(binaryTree.FindNode(target => target == 9), child4);

            Assert.AreEqual(binaryTree.FindNode(target => target == 13), child6);

            Assert.AreEqual(binaryTree.FindNode(target => target == 57), null);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:26,代码来源:FindNode.cs

示例6: DuplicateKeysNotAllowed

        public void DuplicateKeysNotAllowed()
        {
            BinaryTree<int, string> tree = new BinaryTree<int, string>();

            tree.Add(3, "a");
            tree.Add(3, "a");
        }
开发者ID:xoxota99,项目名称:HandyCollections,代码行数:7,代码来源:BinaryTreeTest.cs

示例7: Add_ToFullIntTree_ExpandsTree

 public void Add_ToFullIntTree_ExpandsTree()
 {
     BinaryTree<int> tree = new BinaryTree<int>(new int[] { 54, 25, 316, 4, 55, 6, });
     tree.Add(11);
     tree.Add(41);
     tree.Add(111);
     Assert.AreEqual(9, tree.Count);
 }
开发者ID:helenakolodko,项目名称:DataStructures,代码行数:8,代码来源:BinaryTreeTest.cs

示例8: IndexTest

 public void IndexTest()
 {
     var d = new BinaryTree<int, bool>();
     d.Add(10, true);
     d.Add(20, true);
     d.Add(30, true);
     d.Add(40, true);
     d.Add(25, true);
     Assert.AreEqual(2, d.IndexOfKey(25));
 }
开发者ID:sam0737,项目名称:hellosam.net.collections,代码行数:10,代码来源:BinaryTreeTest.cs

示例9: CountTest

 public void CountTest()
 {
     var tree = new BinaryTree<int>();
     tree.Add(new BinaryTreeNode<int>(1));
     Assert.AreEqual(1, tree.Count);
     tree.Add(new BinaryTreeNode<int>(2));
     Assert.AreEqual(2, tree.Count);
     tree.Add(new BinaryTreeNode<int>(0));
     Assert.AreEqual(3, tree.Count);
 }
开发者ID:codenetio,项目名称:DataStructures.BinaryTree,代码行数:10,代码来源:BinaryTreeTests.cs

示例10: BinaryTreeAddLeaf

 public void BinaryTreeAddLeaf()
 {
     var tree = new BinaryTree<int>();
     tree.Add(4);
     tree.Add(1);
     tree.Add(10);
     tree.ShouldContain(1);
     tree.ShouldContain(4);
     tree.ShouldContain(10);
 }
开发者ID:RazvanHidan,项目名称:Probleme,代码行数:10,代码来源:BinaryTreeTest.cs

示例11: Creation

 public void Creation()
 {
     BinaryTree<int> Tree = new BinaryTree<int>();
     Tree.Add(1);
     Tree.Add(2);
     Tree.Add(0);
     Tree.Add(-1);
     Assert.Equal(-1, Tree.MinValue);
     Assert.Equal(2, Tree.MaxValue);
 }
开发者ID:gwilkinson,项目名称:Craig-s-Utility-Library,代码行数:10,代码来源:BTree.cs

示例12: BinaryTree_Test

        public void BinaryTree_Test()
        {
            BinaryTree<int> tree = new BinaryTree<int>();
            tree.Add(5);
            tree.Add(10);
            tree.Add(80);
            tree.Add(5);
            tree.Add(2);

            Assert.AreEqual(4, tree.Count);
        }
开发者ID:AnnZanevskaya,项目名称:ASP.NET.Zanevskaya.FinalDay,代码行数:11,代码来源:BinaryTreeTest.cs

示例13: Main

 /// <summary>
 /// Main program method
 /// </summary>
 /// <param name="args"></param>
 private static void Main(string[] args)
 {
     var tree = new BinaryTree<int>();
     tree.Add(5);
     tree.Add(3);
     tree.Add(6);
     tree.Print();
     tree.Delete(6);
     tree.Print();
     Console.WriteLine(tree.Contains(6));
 }
开发者ID:Ivan-Nebogatikov,项目名称:Homeworks,代码行数:15,代码来源:Program.cs

示例14: DeleteTest2

 public void DeleteTest2()
 {
     var tree = new BinaryTree<int>();
     tree.Add(4);
     tree.Add(1);
     tree.Add(3);
     tree.Add(2);
     tree.Add(5);
     tree.Delete(4);
     Assert.IsTrue(tree.Contains(3));
 }
开发者ID:Ivan-Nebogatikov,项目名称:Homeworks,代码行数:11,代码来源:BinaryTreeTests.cs

示例15: BinaryTreeTest_Add

        public void BinaryTreeTest_Add()
        {
            BinaryTree<int> tree = new BinaryTree<int>();

            tree.Add(6);
            tree.Add(3);
            tree.Add(9);
            tree.Add(1);
            tree.Add(4);

            int i = 0;
        }
开发者ID:AlexanderChechet,项目名称:ASP.NET.AlexanderChechet.Test,代码行数:12,代码来源:BinaryTreeTest.cs


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