Before sorting, the unsorted array is displayed, and then the QuickSort algorithm is applied. The sorted array is then presented to the user. Throughout the sorting process, the console output includes detailed information about the partitioning steps, comparisons, and swaps.
Input Collection
The user is prompted to input the number of elements in the array, and subsequently, the values for each element are entered interactively.
Array Display (Before Sorting)
The unsorted array is displayed to the console, providing a visual representation of the initial state.
QuickSort Implementation
The QuickSort algorithm is employed to efficiently sort the array. The process involves recursive partitioning and swapping elements based on a chosen pivot.
Partitioning
The Partition method selects a pivot element, and two pointers (l and r) traverse the array from the left and right sides, respectively. Elements are compared to the pivot, and if needed, they are swapped. The detailed console output showcases the comparisons, swaps, and the resulting array after each partitioning step.
Recursive Calls
The QuickSort method orchestrates the recursive calls to sort subarrays. It checks whether there are elements to the left or right of the pivot and makes recursive calls accordingly.
Output
Finally, the sorted array is displayed to the console, providing the user with the result of the QuickSort algorithm.