fork download
  1. public void sort(int[] data) {
  2. if (data != null) {
  3. quickSort(data, data.length);
  4. }
  5. }
  6. private void quickSort(int[] data, int count) {
  7. if (count <= 1) {
  8. return;
  9. }
  10. int[] largeData = new int[count];
  11. int[] smallData = new int[count];
  12. int largeCount = 0;
  13. int smallCount = 0;
  14. int pivot = data[0];
  15. for (int index = 1; index < count; index ++) {
  16. if (data[index] > pivot) {
  17. largeData[largeCount] = data[index];
  18. largeCount ++;
  19. }
  20. else {
  21. smallData[smallCount] = data[index];
  22. smallCount ++;
  23. }
  24. }
  25. quickSort(largeData, largeCount);
  26. quickSort(smallData, smallCount);
  27. int sortedIndex = 0;
  28. for (int smallIndex = 0; smallIndex < smallCount; smallIndex ++) {
  29. data[sortedIndex] = smallData[smallIndex];
  30. sortedIndex ++;
  31. }
  32. data[sortedIndex] = pivot;
  33. sortedIndex ++;
  34. for (int largeIndex = 0; largeIndex < largeCount; largeIndex ++) {
  35. data[sortedIndex] = largeData[largeIndex];
  36. sortedIndex ++;
  37. }
  38. }
  39.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty