int main(int argc, char *argv[] )
{
- char dato[20];
- char *z;
- int i, *pos;
- int len = 11;
- int size;
-
- strcpy( dato,"RDARCAAAABB");
+ int buff[BUFSIZ];
+ int *pos;
+ int len;
+ int i;
+
+ len = fread(buff, 1, BUFSIZ, stdin);
+ buff[len] = '\0';
+
+ pos = jacu_mtf(buff, len);
- /*printf("la posicion de R es: %d\n",get_pos(z, len, 'R'));*/
- pos = jacu_mtf(dato, len);
-
for(i=0; i<len; i++)
printf("%d ", pos[i]);
printf("\n");
-
- /* XXX free(z); <-- NUNCA SE USA! */
+
free(pos);
-
-return 0;
+
+ return 0;
}
+
{
int i;
for(i=0; i<len; i++)
- printf("%c", z[i]);
- printf("\n");
+ fprintf(stderr, "%c", z[i]);
+ fprintf(stderr, "\n");
}
int comparar(const void *d1, const void *d2)
pos = (int*)malloc(len*sizeof(int));
z = jacu_buscar_z(datos, len, &size);
- printf("Z original = ");
+ fprintf(stderr, "Z original = ");
print_z(z, size);
- printf("SIZE = %d\n", size);
+ fprintf(stderr, "SIZE = %d\n", size);
/*z[0]='A';z[1]='B';z[2]='C';z[3]='D';z[4]='R';*/
/* Ordeno */
qsort(z, size, 1, comparar);
- printf("Z ordenado = ");
+ fprintf(stderr, "Z ordenado = ");
print_z(z, size);
for(i=0; i<len; i++){
pos[i] = get_pos(z, size, datos[i]);
- printf("vino %c emiti: %d\n",datos[i], pos[i]);
+ fprintf(stderr, "vino %c emiti: %d\n",datos[i], pos[i]);
if (pos[i] != 0)
pop_front(z,pos[i]);
print_z(z, size);