fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. int[] a ={4,2,7,3,5};
  14. sort(a,0,4);
  15. for(int i:a){
  16. System.out.println(i + " ");
  17. }
  18. }
  19.  
  20. public static void sort(int[] a, int low, int high){
  21.  
  22. if(low<high){
  23. int i = partition(a,low,high);
  24. sort(a,low,i-1);
  25. sort(a,i+1,high);
  26.  
  27. }
  28.  
  29. }
  30. public static int partition(int[] a, int low, int high){
  31. int pivot = a[high];
  32. int i=low,j=low;
  33. for(;j<high;j++){
  34. if(a[j]<pivot){
  35. int temp = a[j];
  36. a[j] = a[i];
  37. a[i] = temp;
  38. i++;
  39. }
  40. }
  41. int temp = a[j];
  42. a[j] = a[i];
  43. a[i] = temp;
  44. return i;
  45. }
  46. }
Success #stdin #stdout 0.05s 4575232KB
stdin
Standard input is empty
stdout
2 
3 
4 
5 
7