-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
58 lines (42 loc) · 1.53 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Linq;
namespace QuickSort
{
abstract class sorter
{
protected String name { get; }
public String GetName() { return name; }
public sorter(String name) { this.name = name; }
public abstract void sort(int[] tosort);
protected static bool verifySorted(int[] arr) // Helper function to verify the sorting algo worked properly.
{
var sorted = new int[arr.Length];
arr.CopyTo(sorted, 0); // Creates copy of arr to compare to
Array.Sort(sorted);
return sorted.SequenceEqual(arr); // Checks implemented sort is equal to properly sorted array
}
}
class Program
{
static void Main(string[] args)
{
Random rand = new Random();
int[] tosort = new int[100000];
for (int i = 0; i < tosort.Length; i++)
{
tosort[i] = rand.Next(0, 500000); //populates an array of 10000 random ints
}
var timer = new System.Diagnostics.Stopwatch();
var sorters = new System.Collections.Generic.List<sorter>();
sorters.Add(new BasicRecursiveQuicksort());
sorters.Add(new OptimizedQuicksort());
foreach (var s in sorters)
{
timer.Reset();
timer.Start();
s.sort(tosort);
Console.WriteLine("{1} sort, Elapsed={0}", timer.Elapsed, s.GetName());
}
}
}
}