Professional Documents
Culture Documents
Algoritmi de Sortare Win Eof
Algoritmi de Sortare Win Eof
h>
#include <stdlib.h>
#include <time.h>
while (1) {
do ++i; while (a[i] <= pivot && i <= r);
do --j; while (a[j] > pivot);
if (i >= j) break;
t = a[i];
a[i] = a[j];
a[j] = t;
}
t = a[l];
a[l] = a[j];
a[j] = t;
return j;
}
if (l < r) {
j = partition(a, l, r);
quickSort(a, l, j - 1);
quickSort(a, j + 1, r);
}
void merge(int *A, int *L, int leftCount, int *R, int rightCount) {
int i, j, k;
i = 0;
j = 0;
k = 0;
while (i < leftCount && j < rightCount) {
if (L[i] < R[j]) A[k++] = L[i++];
else A[k++] = R[j++];
}
while (i < leftCount) A[k++] = L[i++];
while (j < rightCount) A[k++] = R[j++];
}
done = 0;
while ((root * 2 <= bottom) && (!done)) {
if (root * 2 == bottom)
maxChild = root * 2;
else if (numbers[root * 2] > numbers[root * 2 + 1])
maxChild = root * 2;
else
maxChild = root * 2 + 1;
int main() {
srand(time(NULL));
printf("introduceti dimensiunea vectorului: ");
int n;
scanf("%d", &n);
int i = 0;
int *vector;
vector = malloc(sizeof(int) * n);
for (i = 0; i < n; i++) {
vector[i] = 0;
}
for (i = 0; i < n; i++) {
int ran = rand();
// if (!ran) {
// i--;
// continue;
// }
// int k = 0;
// int exist = 0;
// for (k = 0; k < i; k++) {
// if (vector[k] == ran) {
// exist = 1;
// }
// }
// if (exist) {
// i--;
// continue;
// }
vector[i] = ran;
}
printf("a inceput sortarea\n");
bubbleSort(vector, n);
// shellSort(vector, n);
// quickSort(vector, 0, n);
// mergeSort(vector, n);
// heapSort(vector, n);
// qsort(vector, n, sizeof(int), &compareInt); //qsort implementarea din
biblioteca standard C
int notOk = 0;
for (i = 0; i < n; i++) {
int j;
for (j = i + 1; j < n; j++) {
if (vector[i] == vector[j]) {
notOk = 1;
}
}
}
if (notOk) printf("Vectorul suprapune valorile\n");
checkIfVectorIsSorted(vector, n);
for (i = 0; i < n; i++) {
printf("%d ", vector[i]);
}
free(vector);
return 0;
}