本文整理汇总了C#中SortableCollection.BinarySearch方法的典型用法代码示例。如果您正苦于以下问题:C# SortableCollection.BinarySearch方法的具体用法?C# SortableCollection.BinarySearch怎么用?C# SortableCollection.BinarySearch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortableCollection
的用法示例。
在下文中一共展示了SortableCollection.BinarySearch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MethodShouldReturnFalseWhenItemDoesnotExists
public void MethodShouldReturnFalseWhenItemDoesnotExists()
{
var collection = new SortableCollection<int>(new[] { 52, 111, 33, 33, 46, 1125, 1 });
Assert.IsFalse(collection.BinarySearch(1111));
Assert.IsFalse(collection.BinarySearch(-52));
Assert.IsFalse(collection.BinarySearch(0));
}
示例2: TesBinarySearchtWithEmptyCollection
public void TesBinarySearchtWithEmptyCollection()
{
SortableCollection<int> collection = new SortableCollection<int>();
bool result = collection.BinarySearch(15);
Assert.IsFalse(result);
result = collection.BinarySearch(0);
Assert.IsFalse(result);
result = collection.BinarySearch(-1);
Assert.IsFalse(result);
}
示例3: TestForSingleItem
public void TestForSingleItem()
{
SortableCollection<string> collection = new SortableCollection<string>(
new List<string>() { "1" });
Assert.IsTrue(collection.LinearSearch("1"), "Linear search failed on single item collection");
Assert.IsTrue(collection.BinarySearch("1"), "Binary search failed on single item collection");
Assert.IsFalse(collection.LinearSearch("2"),
"Linear search failed on single item collection - non-existing item");
Assert.IsFalse(collection.BinarySearch("2"),
"Binary search failed on single item collection - non-existing item");
}
示例4: TestForOddItems
public void TestForOddItems()
{
SortableCollection<string> collection = new SortableCollection<string>(
new List<string>() { "5", "1", "4", "1", "6" });
Assert.IsTrue(collection.LinearSearch("1"), "Linear search failed on odd items collection");
collection.Sort(new SelectionSorter<string>());
Assert.IsTrue(collection.BinarySearch("1"), "Binary search failed on odd items collection");
Assert.IsFalse(collection.LinearSearch("2"),
"Linear search failed on odd items collection - non-existing item");
Assert.IsFalse(collection.BinarySearch("2"),
"Binary search failed on odd items collection - non-existing item");
}
示例5: TesBinarySearchtWithOneMissingElement
public void TesBinarySearchtWithOneMissingElement()
{
SortableCollection<int> collection = new SortableCollection<int>(
new int[] { 3 });
bool result = collection.BinarySearch(15);
Assert.IsFalse(result);
result = collection.BinarySearch(0);
Assert.IsFalse(result);
result = collection.BinarySearch(-1);
Assert.IsFalse(result);
}
示例6: TesBinarySearchTrivialCase
public void TesBinarySearchTrivialCase()
{
SortableCollection<int> collection = new SortableCollection<int>(
new int[] { -33, -21, 0, 1, 2, 2, 4, 5, 6, 7, 12, 15 });
bool result = collection.BinarySearch(2);
Assert.IsTrue(result);
result = collection.BinarySearch(4);
Assert.IsTrue(result);
result = collection.BinarySearch(5);
Assert.IsTrue(result);
result = collection.BinarySearch(6);
Assert.IsTrue(result);
}
示例7: BinarySearchShouldWorkCorrectlyWithEmptyCollection
public void BinarySearchShouldWorkCorrectlyWithEmptyCollection()
{
var collection = new SortableCollection<int>();
var found = collection.BinarySearch(21);
Assert.IsFalse(found, "Element is found in empty collection!");
}
示例8: TestBinarySearchWithExistingRepeatingElementInCollection
public void TestBinarySearchWithExistingRepeatingElementInCollection()
{
var collection = new SortableCollection<int>(new[] { 101, 101, 33, 22, 11, 0 });
var result = collection.BinarySearch(101);
Assert.IsTrue(result, "Element not found");
}
示例9: TestBinarySearchWithExistingElementInMiddlePositionOddCountOfElements
public void TestBinarySearchWithExistingElementInMiddlePositionOddCountOfElements()
{
var collection = new SortableCollection<int>(new[] { 49, 101, 33, 22, 11, 0, 17 });
var result = collection.BinarySearch(22);
Assert.IsTrue(result, "Element not found");
}
示例10: TestBinarySearchWithExistingElementInFirstPositionEvenCountOfElements
public void TestBinarySearchWithExistingElementInFirstPositionEvenCountOfElements()
{
var collection = new SortableCollection<int>(new[] { 49, 101, 33, 22, 11, 0 });
var result = collection.BinarySearch(49);
Assert.IsTrue(result, "Element not found");
}
示例11: TestBinarySearchWithEmptyCollection
public void TestBinarySearchWithEmptyCollection()
{
var collection = new SortableCollection<int>();
var result = collection.BinarySearch(101);
Assert.IsFalse(result, "Element found in empty collection");
}
示例12: TestBinarySearchWithCollectionOfEqualElements
public void TestBinarySearchWithCollectionOfEqualElements()
{
var collection = new SortableCollection<int>(new[] { 101, 101, 101, 101, 101 });
var result = collection.BinarySearch(101);
Assert.IsTrue(result, "Element not found");
}
示例13: Main
static void Main()
{
var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
Console.WriteLine("All items before sorting:");
Console.WriteLine(collection);
Console.WriteLine("SelectionSorter result:");
collection.Sort(new SelectionSorter<int>());
Console.WriteLine(collection);
Console.WriteLine("Quicksorter result:");
collection.Sort(new Quicksorter<int>());
Console.WriteLine(collection);
Console.WriteLine("MergeSorter result:");
collection.Sort(new MergeSorter<int>());
Console.WriteLine(collection);
Console.WriteLine("Linear search 101:");
Console.WriteLine(collection.LinearSearch(101));
Console.WriteLine("Binary search 101:");
Console.WriteLine(collection.BinarySearch(101));
Console.WriteLine("Shuffle:");
collection.Shuffle();
Console.WriteLine(collection);
Console.WriteLine("Shuffle again:");
collection.Shuffle();
Console.WriteLine(collection);
}
示例14: Main
public static void Main()
{
List<int> numbers = new List<int>() {1,3,4,6,7,8,9,10,23,42};
SortableCollection<int> sortableCollection = new SortableCollection<int>(numbers);
Console.WriteLine(sortableCollection.BinarySearch(-12));
}
示例15: Main
internal static void Main(string[] args)
{
var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
Console.WriteLine("All items before sorting:");
collection.PrintAllItemsOnConsole();
Console.WriteLine("SelectionSorter result:");
collection.Sort(new SelectionSorter<int>());
collection.PrintAllItemsOnConsole();
collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
Console.WriteLine("Quicksorter result:");
collection.Sort(new QuickSorter<int>());
collection.PrintAllItemsOnConsole();
collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
Console.WriteLine("MergeSorter result:");
collection.Sort(new MergeSorter<int>());
collection.PrintAllItemsOnConsole();
Console.WriteLine("Linear search 101:");
Console.WriteLine(collection.LinearSearch(101) + Environment.NewLine);
Console.WriteLine("Binary search 101:");
Console.WriteLine(collection.BinarySearch(101) + Environment.NewLine);
Console.WriteLine("Shuffle:");
collection.Shuffle();
collection.PrintAllItemsOnConsole();
Console.WriteLine("Shuffle again:");
collection.Shuffle();
collection.PrintAllItemsOnConsole();
}