0

I have this code and i am intenting sort the output, but

#include <iostream> 
#include <string.h>
using namespace std;

/* Prototipo de función */
void Permutaciones(char *, int l=0); 
char *cadena[200];
int m=0;
int main() {
   char palabra[13];
   cin>>palabra;

   Permutaciones(palabra);

    cout<<cadena[18];

   return 0;
}

void Permutaciones(char * cad, int l) {
   char c;    /* variable auxiliar para intercambio */
   int i, j;  /* variables para bucles */
   int n = strlen(cad);

   for(i = 0; i < n-l; i++) {
      if(n-l > 2){
        Permutaciones(cad, l+1);
      } 
      else {
            cadena[m]=cad;
            cout<<m<<endl;
            m++;            
      }
      /* Intercambio de posiciones */
      c = cad[l];
      cad[l] = cad[l+i+1];
      cad[l+i+1] = c;
      if(l+i == n-1) {
         for(j = l; j < n; j++){
            cad[j] = cad[j+1];
         } 
         cad[n] = 0;
      }
   }
}

I intent creating a global array of chars (cadena), but not works.

For example the user write bca then the program print:

bca
bac
cba
cab
abc
acb

But i need that the program print sorted, for example:

abc
acb
bac
bca
cab
cba

Could you please help me?

I do not how i can do it.

Code Geas Coder
  • 1,839
  • 4
  • 23
  • 29

0 Answers0