Advertisement
DevMakoto

QuickSort.VFP

Nov 21st, 2015
1,348
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CLEAR
  2.  
  3. PUBLIC ARRAY A[10]
  4. A[1] = 90
  5. A[2] = 70
  6. A[3] = 100
  7. A[4] = 60
  8. A[5] = 10
  9. A[6] = 40
  10. A[7] = 30
  11. A[8] = 80
  12. A[9] = 20
  13. A[10] = 50
  14.  
  15. QUICKSORT(@A,1,10)
  16.  
  17. FOR K = 1 TO 10
  18.    @K,0 SAY A[K]
  19. ENDFOR
  20.  
  21. FUNCTION QUICKSORT
  22. LPARAMETERS A, PRIMERO, ULTIMO
  23. I = PRIMERO
  24. J = ULTIMO
  25. TEMP = 0
  26. CENTRO = INT ((I + J) / 2)
  27. PIVOTE = A[CENTRO]
  28.  
  29.     DO WHILE I < J
  30.         DO WHILE A[I] < PIVOTE
  31.             I = I + 1
  32.         ENDDO
  33.         DO WHILE A[J] > PIVOTE
  34.             J = J - 1
  35.         ENDDO
  36.         IF I <= J
  37.             TEMP = A[I]
  38.             A[I] = A[J]
  39.             A[J] = TEMP
  40.             I = I + 1
  41.             J = J - 1
  42.         ENDIF
  43.     ENDDO
  44.  
  45.     IF PRIMERO < J
  46.         QUICKSORT(@A, PRIMERO, J)
  47.     ENDIF
  48.     IF ULTIMO > I
  49.         QUICKSORT(@A, I, ULTIMO)
  50.     ENDIF
  51.  
  52. ENDFUNC
Advertisement
RAW Paste Data Copied
Advertisement