Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int swap(char *x, char * y){
- char string[1000];
- strcpy(string, x);
- strcpy(x, y);
- strcpy(y, string);
- return 0;
- }
- int vetor_ordena_qsort(vetor* vec){
- int *left=0;
- int *right=vec->tamanho-1;
- int i, j, tamanho = right-left+1;
- if (tamanho<2) {
- return;
- }
- else {
- int pos = rand()%tamanho + left; //determina pivot aleatorio.
- swap(&vec->elementos[pos].str, &vec->elementos[right].str); //coloca o pivot no fim.
- i = left; j = right-1; //passo de partiçao.
- while (1) {
- while (strcmp(vetor_elemento(vec, i), vetor_elemento(vec, right))<0 && i < right) i++;
- while (strcmp(vetor_elemento(vec, right), vetor_elemento(vec, j))<0 && j>=0) j--;
- if (i < j) swap(&vec->elementos[i].str, &vec->elementos[j].str);
- else break;
- }
- swap(&vec->elementos[i].str, &vec->elementos[right].str);
- vetor_ordena_qsort(vec);
- vetor_ordena_qsort(vec, i+1, right);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement