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>()); //Console.WriteLine(collection); }
public static void Main(string[] args) { const int NumberOfElementsToSort = 100; const int MaxValue = 999; 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(MaxValue)); Console.WriteLine(collectionToSort); var collection = new SortableCollection <int>(2, -1, 5, 0, -3); Console.WriteLine(collection); collection.Sort(new QuickSorter <int>()); Console.WriteLine(collection); var collectionToShuflle = new SortableCollection <int>(Enumerable.Range(0, 100).ToArray()); collectionToShuflle.Shuffle(); Console.WriteLine(collectionToShuflle); }
public static void Main(string[] args) { const int NumberOfElementsToSort = 100; const int MaxValue = 1500; 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>()); Console.WriteLine(collection); // Fisher-Yates shuffle var arrayyyyy = collection.ToArray(); collection.Shuffle(arrayyyyy); Console.WriteLine(string.Join(" ", arrayyyyy)); }
public static void Main(string[] args) { const int NumberOfElementsToSort = 100; const int MaxValue = 999; 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); Console.WriteLine(); var collection = new SortableCollection <int>(2, -1, 5, 0, -3); Console.WriteLine(collection); collection.Sort(new Quicksorter <int>()); Console.WriteLine(collection); Console.WriteLine(); var mergeCollection = new SortableCollection <int>(10, -39, 19, 0, -16, 7, 9, 12, -4); Console.WriteLine(mergeCollection); mergeCollection.Sort(new MergeSorter <int>()); Console.WriteLine(mergeCollection); Console.WriteLine(); var heapCollection = new SortableCollection <int>(10, -39, 19, 0, -16, 7, 9, 12, -4); Console.WriteLine(heapCollection); heapCollection.Sort(new HeapSorter <int>()); Console.WriteLine(heapCollection); Console.WriteLine(); var unshuffledCollection = new SortableCollection <int>(10, 9, -8, 6, 13, -25, 7, 4, 1, 0); Console.WriteLine(unshuffledCollection); for (int i = 1; i <= 10; i++) { unshuffledCollection.Shuffle(); Console.WriteLine(unshuffledCollection); } }
public static void Main(string[] args) { const int NumberOfElementsToSort = 100; const int MaxValue = 999; 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); Console.WriteLine(new string('*', 20)); var collection = new SortableCollection <int>(2, -1, 5, 0, -3); Console.WriteLine(collection); collection.Sort(new Quicksorter <int>()); Console.WriteLine(collection); Console.WriteLine(new string('*', 20)); var items = new List <int> { 1, 2, 3, 4, 5, 6 }; Console.WriteLine(string.Join(",", items)); var shuffler = new SortableCollection <int>(); items = shuffler.Shuffle(items).ToList(); Console.WriteLine(string.Join(",", items)); var collectionSort = new SortableCollection <int>(new[] { 6, 5, 8, 3, 5, 0, 15, 6 }); collectionSort.Sort(new HeapSorter <int>()); Console.WriteLine(String.Format("Result: {0}", collectionSort)); }
public static void Main(string[] args) { const int NumberOfElementsToSort = 100; const int MaxValue = 999; 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 InsertionSorter <int>()); Console.WriteLine(collectionToSort); Console.WriteLine(); collectionToSort.Shuffle(); Console.WriteLine(collectionToSort); }