X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/blobdiff_plain/a9564429c158d89dfc16a0ba3f2df2993de1d12f..36bc6edbde4e6e82d6b946543c7cdb4e5c2af287:/otros/mtf/mtf.c diff --git a/otros/mtf/mtf.c b/otros/mtf/mtf.c index e8b9f05..efd2b72 100644 --- a/otros/mtf/mtf.c +++ b/otros/mtf/mtf.c @@ -1,7 +1,7 @@ #include "mtf.h" /****privadas*****/ -int no_pertenece(char *z, char c); +int no_pertenece(char *z, char c, int len); void pop_front(char *z, int pos); @@ -16,6 +16,15 @@ void print_z(char *z, int len) printf("\n"); } +int comparar(const void *d1, const void *d2) +{ + char *c1, *c2; + + c1 = (char *)d1; + c2 = (char *)d2; + + return (*c1) - (*c2); +} int *jacu_mtf(char *datos, int len) { @@ -23,12 +32,17 @@ int *jacu_mtf(char *datos, int len) int *pos; int i, size; - pos = (int*)malloc(len); + pos = (int*)malloc(len*sizeof(int)); z = jacu_buscar_z(datos, len, &size); printf("Z original = "); print_z(z, size); printf("SIZE = %d\n", size); - z[0]='A';z[1]='B';z[2]='C';z[3]='D';z[4]='R'; + /*z[0]='A';z[1]='B';z[2]='C';z[3]='D';z[4]='R';*/ + /* Ordeno */ + qsort(z, size, 1, comparar); + printf("Z ordenado = "); + print_z(z, size); + for(i=0; i