This solution provides implementations of various sorting algorithms using recursive approaches.
- Bubble Sort (Recursive)
- Selection Sort (Recursive)
- Insertion Sort (Recursive)
- Merge Sort (Recursive)
- Quick Sort
Each sorting algorithm is implemented as a static method within the ArraySort
class. Below are brief instructions on how to use each algorithm:
ArraySort.BubbleSortRecursive(array, array.Length);
ArraySort.SelectionSortRecursive(array, 0);
ArraySort.InsertionSortRecursiveByIndex(array, 1);
ArraySort.InsertionSortRecursiveByLength(array, array.Length);
ArraySort.MergeSort(array, 0, array.Length - 1);
ArraySort.QuickSort(array, 0, array.Length - 1);
This method is included in the solution but is not part of the sorting algorithms. It performs a binary search on a sorted array.
ArraySort.BinarySearch(sortedArray);
int[] array = { 5, 3, 8, 4, 2, 7, 1, 6 };
ArraySort.MergeSort(array, 0, array.Length - 1);
ArraySort.Show(array); // Output: 1 2 3 4 5 6 7 8
Make sure to replace array
with the array you want to sort in the example usage. Also, ensure that the array is properly initialized before passing it to any of the sorting methods.