本文整理汇总了C#中BinarySearchTree.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# BinarySearchTree.CopyTo方法的具体用法?C# BinarySearchTree.CopyTo怎么用?C# BinarySearchTree.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinarySearchTree
的用法示例。
在下文中一共展示了BinarySearchTree.CopyTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyTo_InOrder_Test
public void CopyTo_InOrder_Test()
{
var bst = new BinarySearchTree<int>() { 90, 50, 150, 20, 75, 95, 175, 5, 25, 66, 80, 92, 111, 166, 200 };
int[] expected = new int[] { 5, 20, 25, 50, 66, 75, 80, 90, 92, 95, 111, 150, 166, 175, 200 };
int[] actual = new int[bst.Count];
bst.CopyTo(actual, 0, TraversalMethod.Inorder);
CollectionAssert.AreEqual(expected, actual, "Inorder bst traversal did not sort correctly");
}
示例2: CopyToTest
public void CopyToTest([PexAssumeUnderTest]int[] elements, int position)
{
PexAssume.IsTrue(position >= 0 && position <= 1000);
BinarySearchTree<int> bst = new BinarySearchTree<int>(elements);
int[] actual = new int[bst.Count + position];
if (position == 0)
{
bst.CopyTo(actual);
}
else
{
bst.CopyTo(actual, position);
}
//CollectionAssert.AreEqual(expected, actual);
PexObserve.ValueForViewing<int[]>("SearchTree Contents", actual);
}
示例3: CopyToStartingSpecifiedIndexTest
public void CopyToStartingSpecifiedIndexTest()
{
BinarySearchTree<int> bst = new BinarySearchTree<int> { 12, 8, 6, 11, 42 };
int[] expected = { 0, 0, 0, 12, 8, 42, 6, 11 };
int[] actual = new int[bst.Count + 3];
bst.CopyTo(actual, 3);
CollectionAssert.AreEqual(expected, actual);
}
示例4: CopyToTest
public void CopyToTest()
{
BinarySearchTree<int> bst = new BinarySearchTree<int> { 12, 8, 6, 11, 42 };
int[] expected = { 12, 8, 42, 6, 11 };
int[] actual = new int[bst.Count];
bst.CopyTo(actual);
CollectionAssert.AreEqual(expected, actual);
}
示例5: CopyToExample
public void CopyToExample()
{
BinarySearchTreeBase<string, int> tree = new BinarySearchTree<string, int>
{
new KeyValuePair<string, int>("cat", 1),
new KeyValuePair<string, int>("dog", 2),
new KeyValuePair<string, int>("canary", 3)
};
// Create a new array of length 3 to copy the elements into.
var values = new KeyValuePair<string, int>[3];
tree.CopyTo(values, 0);
}