SHARE
TWEET

Untitled

a guest Nov 13th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void quicksort_c(angajat a[], int s, int d, int p, int m)//creem functia de sortare
  2. {
  3.     int i = s, j = d, k = p, l = m;//capetii "intervalului" pe care il sortam
  4.     char x[35];//elementul pe car eil comparam
  5.     angajat aux;//variabila de interchimbare
  6.     //ordonarea crescatoare
  7.     strcpy(x, a[(s + d) / 2].nume);
  8.     do {
  9.         while (strcmp(a[i].nume, x) < 0) i++;//mergem pana gasim un elem mai mare decat x
  10.         while (strcmp(a[j].nume, x) > 0) j--;//mergem pana unde gasim un elem mai mic decat x
  11.         if (i <= j)
  12.         {
  13.             aux = a[i]; a[i] = a[j]; a[j] = aux;//interchimbam elementele gasite anterior
  14.             i++; j--;//incrementam/decrementam pt a verivica in continuare
  15.         }
  16.     } while (i <= j);//condita de oprire
  17.     if (s < j) quicksort_c(a, s, j, p, m);
  18.     if (d > i) quicksort_c(a, i, d, p, m);
  19.  
  20.     //ordonarea descrescatoare
  21.     strcpy(x, a[(p + m) / 2].nume);
  22.     do {
  23.         while (strcmp(a[k].nume, x) > 0) k++;
  24.         while (strcmp(a[l].nume, x) < 0) l--;
  25.         if (k <= l)
  26.         {
  27.             aux = a[k]; a[k] = a[l]; a[l] = aux;
  28.             k++; l--;
  29.         }
  30.     } while (k <= l);
  31.     if (p < l) quicksort_c(a, s, d, p, l);
  32.     if (m > k) quicksort_c(a, s, d, k, m);
  33. }
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