Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. Carros[] carritos=new Carros[10];
  2.  
  3. void setup() {
  4. size(900, 600);
  5. for (int i=0; i<carritos.length; i++) {
  6. carritos[i]=new Carros(color(random(255), random(255), random(255)), 0, (height/10*i), random(10));
  7. }
  8. }
  9.  
  10. void draw() {
  11. background(200);
  12.  
  13. for (int i=0; i<10; i++) {
  14. carritos[i].mostrar();
  15. carritos[i].veloc();
  16. }
  17. }
  18. void quickSort(float arr[], int begin, int end) {
  19. if (begin < end) {
  20. int partitionIndex = partition(arr, begin, end);
  21.  
  22. quickSort(arr, begin, partitionIndex-1);
  23. quickSort(arr, partitionIndex+1, end);
  24. }
  25. }
  26. int partition(float arr[], int begin, int end) {
  27. float pivot = arr[end];
  28. int i = (begin-1);
  29.  
  30. for (int j = begin; j < end; j++) {
  31. if (arr[j] <= pivot) {
  32. i++;
  33.  
  34. float swapTemp = arr[i];
  35. arr[i] = arr[j];
  36. arr[j] = swapTemp;
  37. }
  38. }
  39.  
  40. float swapTemp = arr[i+1];
  41. arr[i+1] = arr[end];
  42. arr[end] = swapTemp;
  43.  
  44. return i+1;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement