static void Main(string[] args) { int[] ia = { 5, 4, 8, 6, 4, 7, 3, 1 }; ArraySorter <int> arr = new ArraySorter <int>(ia, 10); Console.WriteLine("Enqueue of item"); arr.Enqueue(2); foreach (int i in arr.items) { Console.Write(i + " "); } Console.WriteLine("\n"); Console.WriteLine("Dequeued first item"); Console.WriteLine(arr.Dequeue() + "\n"); Console.WriteLine("Sorted Descending"); foreach (int i in arr.SortDescending()) { Console.Write(i + " "); } Console.WriteLine("\n"); Console.WriteLine("Sorted with custom lambda"); foreach (int i in arr.Sort((x, y) => x > y)) { Console.Write(i + " "); } Console.WriteLine("\n"); }
static void Main(string[] args) { var input = new[] { 100, 30, 20, 90, 80, 70, 40, 60, 50, 10 }; var arrSorter = new ArraySorter <int>(input, 20); Console.Write("Sorting descending: "); arrSorter.SortDescending(); foreach (var item in arrSorter.Queue) { Console.Write($"{item.ToString()} "); } Console.Write(("\n\nSorting ascending: ")); arrSorter.SortAscending(); foreach (var item in arrSorter.Queue) { Console.Write($"{item.ToString()} "); } Console.Write("\n\nRemoving all elements: "); while (arrSorter.HeapSize > 0) { Console.Write($"\n Removing: {arrSorter.Dequeue().ToString()} \n New Array: "); foreach (var item in arrSorter.Queue) { Console.Write(item.ToString() + " "); } } arrSorter.Enqueue(120); Console.WriteLine("\nInserting 120"); Console.WriteLine($"Dequeuing {arrSorter.Dequeue().ToString()}"); }
public static void Main(string[] args) { Data[] test = new Data[10]; Random rnd = new Random(); for (int i = 0; i < 10; i++) { int num = rnd.Next(1, 100); int num2 = rnd.Next(1, 100); test[i] = new Data(num, num2, "Data priority1: " + num + ", priority2: " + num2); } ArraySorter <Data> arraySorter = new ArraySorter <Data>(test, test.Length); Console.WriteLine("Print random numbers"); foreach (var obj in test) { Console.WriteLine(obj); } Console.WriteLine("----------------------"); Console.WriteLine("Print ascending numbers"); arraySorter.SortAscending(); foreach (var item in arraySorter.Items) { Console.WriteLine(item); } /* * Console.WriteLine("----------------------"); * Console.WriteLine("Print descending numbers"); * arraySorter.SortDescending(); * * foreach (var item in arraySorter.Items) * { * Console.WriteLine(item); * } */ Console.WriteLine("----------------------"); Console.WriteLine("Print ascending after enqueue numbers"); Data data1 = new Data(70, 20, "Data priority1: 70, priority2: 20"); Data data2 = new Data(50, 10, "Data priority1: 50, priority2: 10"); Data data3 = new Data(80, 15, "Data priority1: 80, priority2: 15"); arraySorter.Enqueue(data1); arraySorter.Enqueue(data2); arraySorter.Enqueue(data3); arraySorter.SortAscending(); foreach (var item in arraySorter.Items) { Console.WriteLine(item); } Console.WriteLine("----------------------"); Console.WriteLine("Print ascending after dequeue numbers"); Console.WriteLine("dequeued " + arraySorter.Dequeue()); Console.WriteLine("dequeued " + arraySorter.Dequeue()); arraySorter.SortAscending(); foreach (var item in arraySorter.Items) { Console.WriteLine(item); } Console.WriteLine("----------------------"); Console.WriteLine("Print descending numbers"); arraySorter.SortDescending(); foreach (var item in arraySorter.Items) { Console.WriteLine(item); } Console.WriteLine("----------------------"); Console.WriteLine("Print ascending with comparator on priority2 numbers"); IComparer <Data> comp = new Priority2Comparer(); arraySorter.Sort(comp); foreach (var item in arraySorter.Items) { Console.WriteLine(item); } }