namespace SortingAlgorithms
private const int MIN = 1;
private const int MAX = 1000;
private const int NUM = 1000;
private static int[] data = new int[NUM];
private static int[] data2 = new int[NUM];
public static void Main(string[] args)
Console.WriteLine("Setting up an unsorted list of number from {0} to {1}", MIN, MAX);
for (i = 0; i < NUM; i++)
data[i] = r.Next(MIN, MAX);
for (i = 0; i < NUM; i++)
data2[i] = r.Next(MIN, MAX);
public static void DisplayData()
string numbers = string.Join(", ", data);
Console.WriteLine(numbers);
public static void BubbleSort()
int countercomparison = 0;
for (i = 0; i < NUM - 1; i++)
for (c = 0; c < NUM - 1; c++)
countercomparison = countercomparison + 1;
if (data[c] > data[c + 1])
counterswap = counterswap + 1;
string numbers = string.Join(", ", data);
Console.WriteLine(numbers);
Console.WriteLine("There were {0} swaps in this sort", counterswap);
Console.WriteLine("There were {0} comparisons in this sort", countercomparison);
public static void BubbleSort2()
for (i = 0; i < NUM - 1; i++)
for (c = 0; c < NUM - 1; c++)
countercomp = countercomp + 1;
if (data2[c] > data2[c + 1])
counterswap = counterswap + 1;
string numbers = string.Join(", ", data2);
Console.WriteLine(numbers);
Console.WriteLine("There were {0} swaps in this sort", counterswap);
Console.WriteLine("There were {0} comparisons in this sort", countercomp);
public static void InsertionSort()