using System.Collections.Generic;
public static void Main()
Console.WriteLine("Hello World");
int[] values = {9, 3, 5, 8, 20, 300, 2, 2, 0, -32, 32};
List<int> testValuesToSort = new List<int>(values);
SortUtility test1 = new SortUtility(testValuesToSort, ESortMethods.Bubble);
SortUtility test2 = new SortUtility(testValuesToSort, ESortMethods.Insert);
Console.WriteLine("Goodbye.");
public enum ESortMethods {None, Bubble, Insert, Select, Shell, Merge, Heap, Quick, Quick3}
private List<int> inputList;
private List<int> outputList;
public List<int> InputList
get { return inputList; }
outputList = sortHandler(inputList);
public List<int> OutputList
get { return outputList; }
private set { outputList = value; }
public delegate List<int> Sorter (List<int> listToSort);
private List<int> noSort (List<int> listToSort) {return listToSort;}
private List<int> bubbleSort (List<int> listToSort)
int[] intList = listToSort.ToArray();
for ( int iterator = 0; iterator < intList.Length - 1; iterator++ )
int itemA = intList[iterator];
int itemB = intList[iterator + 1];
cleanPassThrough = false;
int tempHoldingSpot = itemA;
intList[iterator] = itemA;
intList[iterator + 1] = itemB;
} while (cleanPassThrough == false);
return new List<int>(intList);
private List<int> insertionSort (List<int> listToSort)
int arrayLength = listToSort.Count + 1;
int[] arrayToSort = new int[arrayLength];
int[] inputArray = listToSort.ToArray();
for (int i = 0; i < inputArray.Length; i++)
arrayToSort[i] = inputArray[i];
for (int i = 1; i < arrayToSort.Length; i++)
if (arrayToSort[i] > arrayToSort[i - 1])
} else if (arrayToSort[i] < arrayToSort[i - 1])
int movedItem = arrayToSort[i];
for (int backwardsCounter = i; movedItem > 0; backwardsCounter--)
public void WriteToConsole()
Console.WriteLine("Printout of UNSORTED Input (original): ");
foreach (int intItem in InputList)
Console.Write(intItem.ToString());
Console.WriteLine("Printout of SORTED collection: ");
foreach (int intItem in OutputList)
Console.Write(intItem.ToString());
public SortUtility(List<int> input, ESortMethods sortMethod)
inputList = new List<int>(input);
case ESortMethods.Bubble:
sortHandler = bubbleSort;
case ESortMethods.Insert:
sortHandler = insertionSort;
OutputList = sortHandler(input);