本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}