fork download
  1. public class Main {
  2.  
  3. public static void _QuickSort(int lo, int hi, int[] vec) {
  4.  
  5. int i=lo,
  6. j=hi,
  7. pivot = vec[(hi+lo)>>1];
  8.  
  9. while(i<=j) {
  10. while(vec[i]<pivot){ i++; }
  11. while(vec[j]>pivot){ j--; }
  12. if(i<=j){
  13. int tmp = vec[i];
  14. vec[i]=vec[j];
  15. vec[j]=tmp;
  16. i++;j--;
  17. }
  18. }
  19. if(lo<j) _QuickSort(lo,j,vec);
  20. if(i<hi) _QuickSort(i,hi,vec);
  21. }
  22.  
  23. public static void QuickSort(int[] vec) {
  24.  
  25. _QuickSort(0, vec.length - 1, vec);
  26. }
  27.  
  28. public static void main(String args[]) {
  29.  
  30. //declaram un vector de intregi
  31. int[] vector = {7,6,5,-4,3,2,-1,0};
  32.  
  33. //afisam pe ecran un string
  34. System.out.println("vectorul original");
  35.  
  36. //afisam vectorul pe stdout
  37. DisplayVector( vector );
  38.  
  39. QuickSort( vector );
  40.  
  41. //afisam pe ecran un string
  42. System.out.println("vectorul sortat");
  43.  
  44. //afisam inca o data vectorul sortat
  45. DisplayVector( vector );
  46. }
  47.  
  48. public static void DisplayVector(int[] vec) {
  49.  
  50. for(int value: vec) {
  51.  
  52. System.out.print(value + " ");
  53. }
  54.  
  55. System.out.println();
  56. }
  57. }
Success #stdin #stdout 0.11s 55624KB
stdin
Standard input is empty
stdout
vectorul original
7 6 5 -4 3 2 -1 0 
vectorul sortat
-4 -1 0 2 3 5 6 7