Sort given array using quick sort.
Example 1:
Input:
N=6
arr[] = {3, 2, 9 , 1, 15, 10}
Output: {1, 2, 3, 9, 10, 15}
Example 2:
Input:
N=4
arr[] = {15. -2, 1, 18}
Output: {-2, 1, 15, 18}
1. Function partition:-
The partition function takes an integer array arr[], the low index, and the high index as parameters.
It selects a pivot element (typically the last element of the array) and partitions the array into two
subarrays:
Elements less than the pivot on the left.
Elements greater than the pivot on the right.
The pivot is placed in its final sorted position, and its index (the pivot index) is returned.
2. Function quickSort:-
The quickSort function takes an integer array arr[], the low index, and the high index as parameters.
It recursively sorts the subarrays on both sides of the pivot:
The left subarray contains elements smaller than the pivot.
The right subarray contains elements greater than the pivot.
The sorting process continues until the entire array is sorted.
3. Main Function:-
In the main function:
The user inputs the number of elements n.
An integer array arr of size n is declared to store the input elements.
The user inputs the array elements.
The quickSort function is called to sort the array in ascending order using the Quick Sort algorithm.
Finally, the sorted array is printed.