當前位置: 首頁>>代碼示例>>C#>>正文


C# BinarySearchTree.Select方法代碼示例

本文整理匯總了C#中BinarySearchTree.Select方法的典型用法代碼示例。如果您正苦於以下問題:C# BinarySearchTree.Select方法的具體用法?C# BinarySearchTree.Select怎麽用?C# BinarySearchTree.Select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BinarySearchTree的用法示例。


在下文中一共展示了BinarySearchTree.Select方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: CadAddRootNode

 public void CadAddRootNode()
 {
     //Arrange
     var tree = new BinarySearchTree<int, int> {{100, 100}};
     var expected = new[] { 100 }.ToList();
     //Act
     var result = tree.Select(r => r.KeyValue.Value).ToList();
     //Assert
     CollectionAssert.AreEquivalent(expected, result);
 }
開發者ID:Romiko,項目名稱:Dev2,代碼行數:10,代碼來源:BinaryTreeTests.cs

示例3: CanDeleteLeafNode

 public void CanDeleteLeafNode()
 {
     //Arrange
     var tree = new BinarySearchTree<int, int> { { 2, 2 }, { 1, 1 }, { 3, 3 }, { 4, 4 } };
     var expected = new[] { 1, 2, 3 }.ToList();
     //Act
     tree.Delete(4);
     var result = tree.Select(r => r.KeyValue.Value).ToList();
     //Assert
     CollectionAssert.AreEquivalent(expected, result);
 }
開發者ID:Romiko,項目名稱:Dev2,代碼行數:11,代碼來源:BinaryTreeTests.cs

示例4: CanDeleteNodeWithOneLeftChildNestedBinaryTree

 public void CanDeleteNodeWithOneLeftChildNestedBinaryTree()
 {
     //Arrange
     var tree = new BinarySearchTree<int, int> { { 100, 100 }, { 50, 50 }, { 40, 40 }, { 25, 25 }, { 26, 26 }, { 60, 60 }, { 20, 20 } };
     var expected = new[] { 20, 25, 26, 50, 60, 100 }.ToList();
     //Act
     tree.Delete(40);
     var result = tree.Select(r => r.KeyValue.Value).ToList();
     //Assert
     CollectionAssert.AreEquivalent(expected, result);
 }
開發者ID:Romiko,項目名稱:Dev2,代碼行數:11,代碼來源:BinaryTreeTests.cs

示例5: CanDeleteNodeWithOneLeftChild

 public void CanDeleteNodeWithOneLeftChild()
 {
     //Arrange
     var tree = new BinarySearchTree<int, int> { { 9, 9 }, { 1, 1 }, { 3, 3 }, { 2, 2 }, { 10, 10 }, { 11, 11 } };
     var expected = new[] { 1, 2, 9, 10, 11 }.ToList();
     //Act
     tree.Delete(3);
     var result = tree.Select(r => r.KeyValue.Value).ToList();
     //Assert
     CollectionAssert.AreEquivalent(expected, result);
 }
開發者ID:Romiko,項目名稱:Dev2,代碼行數:11,代碼來源:BinaryTreeTests.cs

示例6: CanDeleteRootNodeWithTwoChildrenNestedBinaryTreeUseSuccessor

 public void CanDeleteRootNodeWithTwoChildrenNestedBinaryTreeUseSuccessor()
 {
     //Arrange
     var tree = new BinarySearchTree<int, int> { { 100, 100 }, { 200, 200 }, { 50, 50 }, { 40, 40 }, { 25, 25 }, { 26, 26 }, { 60, 60 }, { 20, 20 } };
     tree.ForceDeleteType = InOrderNode.Successor;
     var expected = new[] { 20, 25, 26, 40, 50, 60, 200 }.ToList();
     //Act
     tree.Delete(100);
     var result = tree.Select(r => r.KeyValue.Value).ToList();
     //Assert
     CollectionAssert.AreEquivalent(expected, result);
 }
開發者ID:Romiko,項目名稱:Dev2,代碼行數:12,代碼來源:BinaryTreeTests.cs

示例7: CanDeleteNodeWithOneRightChildWithNestedBinaryTree

 public void CanDeleteNodeWithOneRightChildWithNestedBinaryTree()
 {
     //Arrange
     var tree = new BinarySearchTree<int, int> { { 9, 9 }, { 1, 1 }, { 3, 3 }, { 10, 10 }, { 4, 4 }, { 6, 6 }, { 5, 5 } };
     var expected = new[] { 1, 4, 5, 6, 9, 10 }.ToList();
     //Act
     tree.Delete(3);
     var result = tree.Select(r => r.KeyValue.Value).ToList();
     //Assert
     CollectionAssert.AreEquivalent(expected, result);
 }
開發者ID:Romiko,項目名稱:Dev2,代碼行數:11,代碼來源:BinaryTreeTests.cs


注:本文中的BinarySearchTree.Select方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。