#include <stdio.h>
#include <string.h>

/* protótipo de função para comparação de dois elementos do vetor */
typedef int (*func_ptr) (char, char);


/* comparação em ordem crescente */
int ordemDecrescente(char a, char b)
{
   return (a > b);
}

/* comparação em ordem decrescente */
int ordemCrescente(char a, char b)
{
   return (a < b);
}


/* Sort genérico*/
void genBubbleSort(char A[], int tam, func_ptr comp) {
  int last, next, tmp;
  int changed = 1;
  for (last = tam-1; last >= 1; last--) {
    changed = 0;
    for (next = 0; next < last; next++) {
      if (comp(A[next], A[next+1])) {
        tmp = A[next]; A[next] = A[next+1]; A[next+1] = tmp;
        changed = 1;
      }
    }
    if (!changed) return;
  }
}

int main(void)
{
   char s[] = "896475312";

   /* assinatura 1, ordem crescente  */
   printf ("antes  %s\n", s);
   genBubbleSort(s, strlen(s), ordemCrescente);
   printf ("depois %s\n\n", s);

   /* assinatura 2, ordem decrescente */
   printf ("antes  %s\n", s);
   genBubbleSort(s, strlen(s), ordemDecrescente);
   printf ("depois %s\n\n", s);

   return 0;
}