Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<stdio.h>
- #include<string.h>
- int partition(int p, int r, char *v[]) {
- int i, j = p;
- char * pivo = v[r], * temp;
- for(i = p; i < r; i++) {
- if(strcmp(v[i], pivo) < 0) {
- temp = v[j];
- v[j] = v[i];
- v[i] = temp;
- j++;
- }
- }
- v[r] = v[j];
- v[j] = pivo;
- return j;
- }
- void quicksort(int p, int r, char *v[]) {
- int q;
- if(p < r) {
- q = partition(p,r,v);
- quicksort(p,q-1,v);
- quicksort(q+1,r,v);
- }
- }
- //usage
- int main(void) {
- char *nomes[] = {"Samuel","Aline","Abner","Luiz","Absolut"};
- quicksort(0,4,nomes);
- int i=0;
- for(i; i < 5; i++)
- printf("%s\n", nomes[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement