本文整理汇总了C#中SortableCollection类的典型用法代码示例。如果您正苦于以下问题:C# SortableCollection类的具体用法?C# SortableCollection怎么用?C# SortableCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SortableCollection类属于命名空间,在下文中一共展示了SortableCollection类的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: 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);
}
示例3: 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 collectionToShuffle = new SortableCollection<int>(1, 2, 3, 4, 5);
Console.WriteLine("Before shufflin` " + collectionToShuffle);
collectionToShuffle.Shuffle();
Console.WriteLine("After shufflin` " + collectionToShuffle);
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);
}
示例4: 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");
}
示例5: TestSortWithMultipleElementsMultipleTimes
public void TestSortWithMultipleElementsMultipleTimes()
{
const int NumberOfAttempts = 10000;
const int MaxNumberOfElements = 1000;
for (int i = 0; i < NumberOfAttempts; i++)
{
var numberOfElements = Random.Next(0, MaxNumberOfElements + 1);
List<int> originalElements = new List<int>(MaxNumberOfElements);
for (int j = 0; j < numberOfElements; j++)
{
originalElements.Add(Random.Next(int.MinValue, int.MaxValue));
}
var collection = new SortableCollection<int>(originalElements);
originalElements.Sort();
collection.Sort(TestSorter);
CollectionAssert.AreEqual(
originalElements,
collection.ToArray(),
"Sort method should sort the elements in ascending order.");
}
}
示例6: 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");
}
示例7: 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");
}
示例8: Test2SectionSortMethod
public void Test2SectionSortMethod()
{
var collection1 = new SortableCollection<int>(new[] { 22, 13, 23, 45, -55, 90, 100, 101, -12, 55, 44 });
collection1.Sort(new SelectionSorter<int>());
var testCollection = new SortableCollection<int>(new[] { -55, -12, 13, 22, 23, 44, 45, 55, 90, 100, 101 });
Assert.Equals(testCollection, collection1);
}
示例9: Test3SectionSortMethod
public void Test3SectionSortMethod()
{
var collection1 = new SortableCollection<string>(new[] { "aaaa", "cccc", "dddd", "cccc", "caaa", "aacc", "bbdd", "ccff", "eerr", "rrtt", "assdd" });
collection1.Sort(new SelectionSorter<string>());
var testCollection = new SortableCollection<int>(new[] { -55, -12, 13, 22, 23, 44, 45, 55, 90, 100, 101 });
Assert.Equals(testCollection, collection1);
}
示例10: SelectionSorterTestWithOneElement
public void SelectionSorterTestWithOneElement()
{
SortableCollection<int> collection = new SortableCollection<int>(new int[] { 5 });
collection.Sort(new SelectionSorter<int>());
Assert.AreEqual(1, collection.Items.Count);
Assert.AreEqual(5, collection.Items[0]);
}
示例11: Test1SectionSortMethod
public void Test1SectionSortMethod()
{
var collection = new SortableCollection<int>(new[] { 22, 13 });
collection.Sort(new SelectionSorter<int>());
var testCollection = new SortableCollection<int>(new[] { 13, 22 });
Assert.Equals(collection,testCollection);
}
示例12: 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);
collection = new SortableCollection<int>(3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48);
Console.WriteLine(collection);
collection.Shuffle();
Console.WriteLine(collection);
//collection.Sort(new Quicksorter<int>());
//Console.WriteLine(collection);
}
示例13: 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);
}
示例14: TestWithASingleItemNotFound
public void TestWithASingleItemNotFound()
{
SortableCollection<int> collection = new SortableCollection<int>(new int[] { 6 });
bool isFound = collection.LinearSearch(4);
Assert.IsFalse(isFound);
}
示例15: MergeSortShouldWorkCorrectlyWithEmptyCollection
public void MergeSortShouldWorkCorrectlyWithEmptyCollection()
{
var collection = new SortableCollection<int>();
collection.Sort(new MergeSorter<int>());
Assert.AreEqual(0, collection.Items.Count, "Collection is not empty after sorting!");
}