Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

matheus__serpa May 19th, 2020 (edited) 1,053 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void troca(int *x, int *y){
  2.     int aux = *x;
  3.     *x = *y;
  4.     *y = aux;
  5. }
  6.  
  7. int particao(int *A, int esq, int dir){
  8.     int pivo = A[dir];
  9.     int j, i = esq;
  10.  
  11.     for(j = esq; j < dir; j++)
  12.         if(A[j] <= pivo){
  13.             troca(&A[i], &A[j]);
  14.             i++;
  15.         }
  16.     troca(&A[i], &A[dir]);
  17.     return i;
  18. }
  19.  
  20. void quick_sort(int *A, int esq, int dir){
  21.     if(esq < dir){
  22.         int pos = particao(A, esq, dir);
  23.         quick_sort(A, esq, pos - 1);
  24.         quick_sort(A, pos + 1, dir);
  25.     }
  26. }
  27.  
  28. int main(){
  29.     int i, A[5] = {4, 7, 1, 5, 3};
  30.  
  31.     for(i = 0; i < 5; i++)
  32.         printf("%d ", A[i]);
  33.  
  34.     printf("\n");
  35.     quick_sort(A, 0, 4);
  36.  
  37.     for(i = 0; i < 5; i++)
  38.         printf("%d ", A[i]);
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top