本文整理汇总了C#中SortableCollection.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# SortableCollection.Sort方法的具体用法?C# SortableCollection.Sort怎么用?C# SortableCollection.Sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortableCollection
的用法示例。
在下文中一共展示了SortableCollection.Sort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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();
Console.WriteLine("SelectionSorter result:");
collection.Sort(new SelectionSorter<int>());
collection.PrintAllItemsOnConsole();
Console.WriteLine();
Console.WriteLine("BubbleSorter result:");
collection.Sort(new BubbleSorter<int>());
collection.PrintAllItemsOnConsole();
Console.WriteLine();
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.BinarySearch(101));
Console.WriteLine();
Console.WriteLine("Shuffle:");
collection.Shuffle();
collection.PrintAllItemsOnConsole();
Console.WriteLine();
Console.WriteLine("Shuffle again:");
collection.Shuffle();
collection.PrintAllItemsOnConsole();*/
}
示例3: 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);
}
示例4: 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);
}
示例5: 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));
}
示例6: TestSelectionSortingWithEmptyCollection
public void TestSelectionSortingWithEmptyCollection()
{
var collection = new SortableCollection<int>();
collection.Sort(new SelectionSorter<int>());
Assert.AreEqual(0, collection.Items.Count, "Collection is not empty after sorting");
}
示例7: 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!");
}
示例8: 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);
}
示例9: 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);
}
示例10: 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.");
}
}
示例11: 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]);
}
示例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: BinarySearchShouldWorkCorrectlyWhenSearchedElementIsNotFound
public void BinarySearchShouldWorkCorrectlyWhenSearchedElementIsNotFound()
{
var collection = new SortableCollection<int>(new int[] { 6, 1, 4, 2, 3, -5, 8 });
collection.Sort(new MergeSorter<int>());
var found = collection.BinarySearch(21);
Assert.IsFalse(found, "Element is found in collection!");
}
示例14: TestBinarySearchResultIsLast
public void TestBinarySearchResultIsLast()
{
int[] input = { 8, 5, 8, 3, 4, 67, 9, 3, 9, -4 };
SortableCollection<int> sortableCol = new SortableCollection<int>(input);
sortableCol.Sort(new MergeSorter<int>());
bool containsItem = sortableCol.BinarySearch(-4);
Assert.IsTrue(containsItem);
}
示例15: LinearSearchShouldWorkCorrectlyWithEmptyCollection
public void LinearSearchShouldWorkCorrectlyWithEmptyCollection()
{
var collection = new SortableCollection<int>();
collection.Sort(new MergeSorter<int>());
var found = collection.LinearSearch(21);
Assert.IsFalse(found, "Element is found in empty collection!");
}