本文整理汇总了C#中SortableCollection.LinearSearch方法的典型用法代码示例。如果您正苦于以下问题:C# SortableCollection.LinearSearch方法的具体用法?C# SortableCollection.LinearSearch怎么用?C# SortableCollection.LinearSearch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortableCollection
的用法示例。
在下文中一共展示了SortableCollection.LinearSearch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MethodShouldReturnFalseWhenItemDoesnotExists
public void MethodShouldReturnFalseWhenItemDoesnotExists()
{
var collection = new SortableCollection<int>(new[] { 52, 111, 33, 33, 46, 1125, 1 });
Assert.IsFalse(collection.LinearSearch(1111));
Assert.IsFalse(collection.LinearSearch(-52));
Assert.IsFalse(collection.LinearSearch(0));
}
示例2: TesLinearSearchtWithEmptyCollection
public void TesLinearSearchtWithEmptyCollection()
{
SortableCollection<int> collection = new SortableCollection<int>();
bool result = collection.LinearSearch(15);
Assert.IsFalse(result);
result = collection.LinearSearch(0);
Assert.IsFalse(result);
result = collection.LinearSearch(-1);
Assert.IsFalse(result);
}
示例3: 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();
collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
Console.WriteLine("SelectionSorter result:");
collection.Sort(new SelectionSorter<int>());
collection.PrintAllItemsOnConsole();
Console.WriteLine();
collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
Console.WriteLine("BubbleSorter result:");
collection.Sort(new BubbleSorter<int>());
collection.PrintAllItemsOnConsole();
Console.WriteLine();
collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
Console.WriteLine("InsertionSorter result:");
collection.Sort(new InsertionSorter<int>());
collection.PrintAllItemsOnConsole();
Console.WriteLine();
collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
Console.WriteLine("Quicksorter result:");
collection.Sort(new QuickSorter<int>());
collection.PrintAllItemsOnConsole();
Console.WriteLine();
collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
Console.WriteLine("MergeSorter result:");
collection.Sort(new MergeSorter<int>());
collection.PrintAllItemsOnConsole();
Console.WriteLine();
Console.WriteLine("Linear search 101:");
Console.WriteLine(collection.LinearSearch(101));
Console.WriteLine();
Console.WriteLine("Binary search 101:");
Console.WriteLine(collection.LinearSearch(101));
Console.WriteLine();
Console.WriteLine("Shuffle:");
collection.Shuffle();
collection.PrintAllItemsOnConsole();
Console.WriteLine();
Console.WriteLine("Shuffle again:");
collection.Shuffle();
collection.PrintAllItemsOnConsole();
}
示例4: 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");
}
示例5: TesLinearSearchtWithOneMissingElement
public void TesLinearSearchtWithOneMissingElement()
{
SortableCollection<int> collection = new SortableCollection<int>(
new int[] { 3 });
bool result = collection.LinearSearch(15);
Assert.IsFalse(result);
result = collection.LinearSearch(0);
Assert.IsFalse(result);
result = collection.LinearSearch(-1);
Assert.IsFalse(result);
}
示例6: 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");
}
示例7: Main
public static void Main()
{
List<int> numbers = new List<int>() { 1,3,5,6,7,3,32,3,5,67,7,4,34,3};
SortableCollection<int> collection = new SortableCollection<int>(numbers);
Console.WriteLine(collection.LinearSearch(7));
}
示例8: 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);
}
示例9: TestLinearSearchWithExistingElementInMiddlePositionOddCountOfElements
public void TestLinearSearchWithExistingElementInMiddlePositionOddCountOfElements()
{
var collection = new SortableCollection<int>(new[] { 49, 101, 33, 22, 11, 0, 17 });
var result = collection.LinearSearch(22);
Assert.IsTrue(result, "Element not found");
}
示例10: TestLinearSearchWithExistingRepeatingElementInCollection
public void TestLinearSearchWithExistingRepeatingElementInCollection()
{
var collection = new SortableCollection<int>(new[] { 101, 101, 33, 22, 11, 0 });
var result = collection.LinearSearch(101);
Assert.IsTrue(result, "Element not found");
}
示例11: TestLinearSearchWithEmptyCollection
public void TestLinearSearchWithEmptyCollection()
{
var collection = new SortableCollection<int>();
var result = collection.LinearSearch(101);
Assert.IsFalse(result, "Element found in empty collection");
}
示例12: TestLinearSearchWithExistingElementInFirstPositionEvenCountOfElements
public void TestLinearSearchWithExistingElementInFirstPositionEvenCountOfElements()
{
var collection = new SortableCollection<int>(new[] { 49, 101, 33, 22, 11, 0 });
var result = collection.LinearSearch(49);
Assert.IsTrue(result, "Element not found");
}
示例13: TestBinarySearch_WithNonExistingItem
public void TestBinarySearch_WithNonExistingItem()
{
var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
var result = collection.LinearSearch(-11);
Assert.AreNotEqual(true, result);
}
示例14: TestLinearSearchWithCollectionOfEqualElements
public void TestLinearSearchWithCollectionOfEqualElements()
{
var collection = new SortableCollection<int>(new[] { 101, 101, 101, 101, 101 });
var result = collection.LinearSearch(101);
Assert.IsTrue(result, "Element not found");
}
示例15: TestWithMultipleItemsNotFound
public void TestWithMultipleItemsNotFound()
{
SortableCollection<int> collection = new SortableCollection<int>(new int[] { 4, 11, -3, 7, 9, 23 });
bool isFound = collection.LinearSearch(235);
Assert.IsFalse(isFound);
}