public void printResult() { int[] arr = new int[] { 12, 11, 13, 5, 6, 7 }; PrintMethod.printArray1("Marge Sort", arr); sort(arr, 0, arr.Length - 1); PrintMethod.printArray("Marge Sort", arr); }
public void printResult() { int[] arr = new int[] { 5, 3, 7, 1, 9, 2, 4, 6, 8 }; PrintMethod.printArray1("Bubble Sort", arr); bubbleSort(arr); PrintMethod.printArray("Bubble Sort", arr); }
public void printResult() { int[] arr = new int[] { 10, 7, 8, 9, 1, 5 }; PrintMethod.printArray1("Quick Sort", arr); sort(arr, 0, arr.Length - 1); PrintMethod.printArray("Quick Sort", arr); }
// Selection sort with in array public void selectionSortArray() { int[] arr = { 64, 25, 12, 22, 11 }; int countLength = arr.Length; Console.WriteLine("Before appling Selection Sort : "); foreach (var item in arr) { Console.Write(item + " "); } Console.WriteLine("\n"); // One by one move boundary of unsorted subarray for (int i = 0; i < countLength - 1; i++) { // Find the minimum element in unsorted array int minIndex = i; for (int j = i + 1; j < countLength; j++) { if (arr[j] < arr[minIndex]) { minIndex = j; } } // Swap the found minimum element with the first // element int temp = arr[minIndex]; arr[minIndex] = arr[i]; arr[i] = temp; } PrintMethod.printArray("Selection Sort", arr); }
public void printResult() { int[] arr = { 2, 4, 5, 3, 1 }; PrintMethod.printArray1("Stooge Sort", arr); stoogesort(arr, 0, arr.Length - 1); Console.WriteLine(); PrintMethod.printArray("Stooge Sort", arr); Console.WriteLine(); }
public void insertionSort() { int[] arr = new int[] { 12, 11, 13, 5, 6 }; int lengthCount = arr.Length; for (int i = 1; i < lengthCount; ++i) { int key = arr[i]; int j = i - 1; /* Move elements of arr[0..i-1], that are * greater than key, to one position ahead * of their current position */ while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j]; j = j - 1; } arr[j + 1] = key; } PrintMethod.printArray("Insertion Sort", arr); }