Advertisement
imk0tter

Untitled

Jul 20th, 2011
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. void permute(char * input, char * next);
  2. void remove(char * destination, char * source, int position);
  3.  
  4. void permute(char * input) {
  5.    char buffer[] =  { 0 };
  6.    permute(input,buffer);
  7. }
  8. void permute(char * input, char * next) {
  9.    if (!input[0]) printf("%s\n",next);
  10.    for (int i = 0; *(input+i); ++i) {
  11.        char buff[128];
  12.        char _buff[128];
  13.  
  14.        remove(buff,input,i);
  15.  
  16.        int len = strlen(next);
  17.  
  18.        memcpy(_buff,input+i,1);
  19.        memcpy(_buff+1,next,len+1);
  20.  
  21.        permute(buff, _buff);
  22.    }
  23. }
  24. void remove(char * output, char * input, int pos) {
  25.    int length = strlen(input), posi = 0;
  26.    for (int i = 0; i <= length; ++i)
  27.        if (pos != i) output[posi++] = *(input+i);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement