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


C# BinarySearchTree.Find方法代码示例

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


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

示例1: BinaryTreeMustSortTheSameAsSortedDictionary

        public void BinaryTreeMustSortTheSameAsSortedDictionary()
        {
            // Arrange
            var asm = Assembly.GetExecutingAssembly();
            var importer = new Importer(asm.GetManifestResourceStream("ClientImport.Tests.records.txt"), ',');
            var dictionary = new SortedDictionary<string, IPerson>();
            var tree = new BinarySearchTree<string, IPerson>();

            //Act
            importer.Data
                           .ToList()
                           .ForEach(record =>
                           {
                               var person = new Person
                               {
                                   FirstName = record.FirstName,
                                   Surname = record.Surname,
                                   Age = Convert.ToInt16(record.Age)
                               };
                               var key = PersonRepository.BuildKey(person, SortKey.SurnameFirstNameAge);
                               if (tree.Find(key) == null)
                                   tree.Add(key, person);
                           }
                              );

            tree
                .ToList()
                .Shuffle() //Shuffle result from binary tree, to test sorting
                .ForEach(r => dictionary.Add(PersonRepository.BuildKey(r.KeyValue.Value, SortKey.SurnameFirstNameAge), r.KeyValue.Value));

            var expected = dictionary.Select(r => r.Value).ToList();
            var actual = tree.Select(n => n.KeyValue.Value).ToList();
            // Assert
            CollectionAssert.AreEqual(expected, actual);
        }
开发者ID:Romiko,项目名称:Dev2,代码行数:35,代码来源:BinaryTreeTests.cs

示例2: Main

        static void Main(string[] args)
        {
            BinarySearchTree<int> tree1 = new BinarySearchTree<int>();

            // test the add method
            tree1.Add(2);
            tree1.Add(1);
            tree1.Add(3);
            tree1.Add(7);
            tree1.Add(5);

            // test the Clone() method
            BinarySearchTree<int> tree2 = (BinarySearchTree<int>)tree1.Clone();

            // test the ToString() method
            Console.WriteLine("Tree 1: {0}", tree1);
            Console.WriteLine("Tree 2: {0}", tree2);

            // test the Equals() method
            Console.WriteLine("The two trees are equal: {0}",
                (tree1 == tree2));

            // test the Delete() method
            tree2.Delete(7);
            Console.WriteLine("After deleting 5 from tree 2: {0}", tree2);

            // test the Find() method
            var node = tree1.Find(3);
            if(node != null)
            {
                Console.WriteLine("3 was found in tree 1");
            }
            else
            {
                Console.WriteLine("3 was NOT found in tree 1");
            }
        }
开发者ID:BlueForeverI,项目名称:OOPHomework,代码行数:37,代码来源:TreeTest.cs


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