QuickSort is a Divide and Conquer algorithm. It picks an element as a pivot and partitions the given array around the picked pivot. Java public class Sort{ public static void main (String []args){ int [] arr = { 3 , 5 , 1 , 6 , 2 , 4 , 8 }; quickSort(arr, 0 , arr. length - 1 ); for ( int x:arr) System. out . print (x+ " " ); } public static int partition ( int arr[], int low, int high){ int pivot = arr[high]; int i = (low- 1 ); for ( int j=low; j<high; j++){ if (arr[j] <= pivot){ i++; int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } int temp = arr[i+ 1 ]; arr[i+ 1 ] = arr[high]; arr[high] = temp; return i+ 1 ; } public static void quickSort ( ...
This blog contains coding/programming and interview questions of MNCs like TCS, Wipro, Infosys, Capgemini, Mindtree, Amazon, Google, Facebook, Flipkart, Cisco, HP, Dell, etc. with placement preparation guides.