1. Quicksort 1 - Partition
  2.  
  3.  
  4. The previous challenges covered Insertion Sort, which is a simple and intuitive sorting algorithm with a running time of . In these next few challenges, we're covering a divide-and-conquer algorithm called Quicksort (also known as Partition Sort). This challenge is a modified version of the algorithm that only addresses partitioning. It is implemented as follows:
  5.  
  6.  
  7.  
  8. public static List<Integer> quickSort(List<Integer> arr) {
  9. // Write your code here
  10. int pivot=arr.get(0);
  11. int i=0;
  12. int j=arr.size();
  13. while(true)
  14. {
  15. do{
  16. i++;
  17. }while(arr.get(i)<pivot);
  18. do{
  19. j--;
  20. }while(arr.get(j)>pivot);
  21. if (i >= j)
  22. {
  23. break;
  24. }
  25. int temp=arr.get(i);
  26. arr.set(i,arr.get(j));
  27. arr.set(j,temp);
  28. }
  29. arr.set(0,arr.get(j));
  30. arr.set(j,pivot);
  31. return arr;
  32.  
  33. }