本文整理汇总了C#中SortableCollection.InterpolationSearch方法的典型用法代码示例。如果您正苦于以下问题:C# SortableCollection.InterpolationSearch方法的具体用法?C# SortableCollection.InterpolationSearch怎么用?C# SortableCollection.InterpolationSearch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortableCollection
的用法示例。
在下文中一共展示了SortableCollection.InterpolationSearch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
const int NumberOfElementsToSort = 22;
const int MaxValue = 150;
var array = new int[NumberOfElementsToSort];
for (int i = 0; i < NumberOfElementsToSort; i++)
{
array[i] = Random.Next(MaxValue);
}
var collectionToSort = new SortableCollection<int>(array);
// !!!!!!!!!!!!!! collectionToSort.Sort(new BucketSorter { Max = MaxValue });
Console.WriteLine(collectionToSort);
var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
Console.WriteLine(collection);
// collection.Sort(new Quicksorter<int>());
collection.Sort(new InsertionSorter<int>());
Console.WriteLine(collection);
Console.WriteLine(collection.InterpolationSearch(0));
}
示例2: TestWithItemToTheRightOfMidpoint
public void TestWithItemToTheRightOfMidpoint()
{
var collection = new SortableCollection<int>(1, 2, 3, 4, 5);
var result = collection.InterpolationSearch(4);
var expected = Array.BinarySearch(collection.ToArray(), 4);
Assert.AreEqual(expected, result);
}
示例3: TestWithEmptyCollectionShouldReturnMissingElement
public void TestWithEmptyCollectionShouldReturnMissingElement()
{
var collection = new SortableCollection<int>();
var result = collection.InterpolationSearch(0);
var expected = Array.BinarySearch(collection.ToArray(), 0);
Assert.AreEqual(expected, result, "No elements are present in an empty collection; method should return -1.");
}
示例4: InterpolationTest5
public void InterpolationTest5()
{
var collection = new SortableCollection<int>(1, 2, 3, 4, 5);
var result = collection.InterpolationSearch(4);
var expected = Array.BinarySearch(collection.ToArray(), 4);
Assert.AreEqual(expected, result);
}
示例5: TestWithItemAtMidpoint
public void TestWithItemAtMidpoint()
{
var collection = new SortableCollection<int>(1, 2, 3, 4, 5);
this.ApplyDelegates(ref collection);
var result = collection.InterpolationSearch(3);
var expected = Array.BinarySearch(collection.ToArray(), 3);
Assert.AreEqual(expected, result);
}
示例6: TestWithMissingElement
public void TestWithMissingElement()
{
var collection = new SortableCollection<int>(-1, 1, 5, 12, 50);
var result = collection.InterpolationSearch(0);
var expected = -1;
Assert.AreEqual(expected, result, "Missing element should return -1.");
}
示例7: TestWithItemAtMidpoint
public void TestWithItemAtMidpoint()
{
var collection = new SortableCollection<int>(1, 2, 3, 4, 5);
var items = collection.Items;
var result = collection.InterpolationSearch(items, 3, interpolator);
var expected = Array.BinarySearch(collection.ToArray(), 3);
Assert.AreEqual(expected, result);
}
示例8: TestWithItemToTheLeftOfMidpoint
public void TestWithItemToTheLeftOfMidpoint()
{
var collection = new SortableCollection<int>(1, 2, 3, 4, 5);
var sorter = new Quicksorter<int>();
collection.Sort(sorter);
var result = collection.InterpolationSearch(collection.ToArray(), 2);
var expected = Array.BinarySearch(collection.ToArray(), 2);
Assert.AreEqual(expected, result);
}
示例9: TestWithEmptyCollectionShouldReturnMissingElement
public void TestWithEmptyCollectionShouldReturnMissingElement()
{
var collection = new SortableCollection<int>();
// the idea for the delegates is given from ttitto
this.ApplyDelegates(ref collection);
var result = collection.InterpolationSearch(0);
var expected = Array.BinarySearch(collection.ToArray(), 0);
Assert.AreEqual(
expected,
result,
"No elements are present in an empty collection; method should return -1.");
}
示例10: TestWithRepeatingItemShouldReturnFirstDiscoveredIndex
public void TestWithRepeatingItemShouldReturnFirstDiscoveredIndex()
{
var collection = new SortableCollection<int>(0, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7);
var result = collection.InterpolationSearch(3);
Assert.AreEqual(2, result);
}
示例11: TestWithMultipleMissingKeysSmallerThanMinimum
public void TestWithMultipleMissingKeysSmallerThanMinimum()
{
const int NumberOfChecks = 10000;
const int NumberOfElements = 1000;
var elements = new int[NumberOfElements];
for (int i = 0; i < NumberOfElements; i++)
{
elements[i] = Random.Next(int.MinValue / 2, int.MaxValue / 2);
}
Array.Sort(elements);
var collection = new SortableCollection<int>(elements);
for (int i = 0; i < NumberOfChecks; i++)
{
var item = Random.Next(int.MinValue, collection.Items[0]);
int result = collection.InterpolationSearch(item);
Assert.AreEqual(-1, result);
}
}
示例12: InterpolationTest9
public void InterpolationTest9()
{
var collection = new SortableCollection<int>(0, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7);
var result = collection.InterpolationSearch(3);
Assert.IsTrue(new int[] { 1, 2, 3, 4 }.Contains(result));
}
示例13: TestWithRepeatingItemShouldReturnFirstDiscoveredIndex
public void TestWithRepeatingItemShouldReturnFirstDiscoveredIndex()
{
var collection = new SortableCollection<int>(0, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7);
var sorter = new InsertionSorter<int>();
collection.Sort(sorter);
var sortedArray = collection.ToArray();
var result = collection.InterpolationSearch(sortedArray, 3);
Assert.AreEqual(4, result);
}
示例14: TestWithMultipleMissingKeysLargerThanMaximum
public void TestWithMultipleMissingKeysLargerThanMaximum()
{
const int NumberOfChecks = 10000;
const int NumberOfElements = 1000;
var elements = new int[NumberOfElements];
for (int i = 0; i < NumberOfElements; i++)
{
elements[i] = Random.Next(int.MinValue / 2, int.MaxValue / 2);
}
Array.Sort(elements);
var collection = new SortableCollection<int>(elements);
var sorter = new Quicksorter<int>();
collection.Sort(sorter);
var sortedArray = collection.ToArray();
for (int i = 0; i < NumberOfChecks; i++)
{
var item = Random.Next(collection.Items[collection.Count - 1], int.MaxValue);
var result = collection.InterpolationSearch(sortedArray, item);
Assert.AreEqual(-1, result);
}
}
示例15: TestWithMultipleKeys
public void TestWithMultipleKeys()
{
const int NumberOfElements = 10000;
var elements = new int[NumberOfElements];
for (int i = 0; i < NumberOfElements; i++)
{
elements[i] = Random.Next(-100, 100);
}
Array.Sort(elements);
var collection = new SortableCollection<int>(elements);
var items = collection.Items;
foreach (var element in elements)
{
var result = collection.InterpolationSearch(items, element, interpolator);
Assert.AreEqual(element, items[result]);
}
}