446,232 Members | 1,689 Online
Need help? Post your question and get tips & solutions from a community of 446,232 IT Pros & Developers. It's quick & easy.

# Learn recursion

 P: n/a I'm trying to learn how to make a scrambling algorithm in C that will turn out all possible permutations of a word without repeating (but repeating can easily be fixed). I found out a few algorithms in comp.lang.c++, but none of them work. I'm using gcc. Jun 25 '06 #1
5 Replies

 P: n/a In article <11*********************@b68g2000cwa.googlegroups. com>, re*******@yahoo.com wrote:I'm trying to learn how to make a scrambling algorithm in C that willturn out all possible permutations of a word without repeating (butrepeating can easily be fixed). I found out a few algorithms incomp.lang.c++, but none of them work. In order to understand recursion, you must first understand recursion. Jun 25 '06 #2

 P: n/a [OP hasn't shown up on news.qwest.net yet]: | In article <11*********************@b68g2000cwa.googlegroups. com>, | re*******@yahoo.com wrote: || I'm trying to learn how to make a scrambling algorithm in C that || will turn out all possible permutations of a word without || repeating (but repeating can easily be fixed). I found out a few || algorithms in comp.lang.c++, but none of them work. Recursion is fun. I came up with the following; but you'll need to clean it up a bit because I didn't check the return value from malloc() and left a debug printf() in place so you can better see what's going on during execution. #include #include #include void permute(char *fixed,char *remain) { unsigned i,len = strlen(fixed); char *newrem; unsigned char c; if (strlen(remain)) { newrem = malloc(1+strlen(remain)); fixed[len+1] = '\0'; for (i=0; i

 P: n/a re*******@yahoo.com posted: I'm trying to learn how to make a scrambling algorithm in C that will turn out all possible permutations of a word without repeating (but repeating can easily be fixed). I found out a few algorithms in comp.lang.c++, but none of them work. I'm using gcc. If you're using C++, check this out: http://en.wikipedia.org/wiki/Template_metaprogramming -- Frederick Gotham Jun 25 '06 #4

 P: n/a #include #include #include void permute(char *fixed,char *remain) { unsigned i,len = strlen(fixed); char *newrem; unsigned char c; if (strlen(remain)) { newrem = malloc(1+strlen(remain)); fixed[len+1] = '\0'; for (i=0; i

 P: n/a Kenny McCormack wrote: In article <11*********************@b68g2000cwa.googlegroups. com>, re*******@yahoo.com wrote:I'm trying to learn how to make a scrambling algorithm in C that willturn out all possible permutations of a word without repeating (butrepeating can easily be fixed). I found out a few algorithms incomp.lang.c++, but none of them work. In order to understand recursion, you must first understand recursion. Ah-hhmmm. In order to understand recursion, you must first understand a *simpler* form the of the recursion. -- +----------------------------------------------------------------+ | Charles and Francis Richmond richmond at plano dot net | +----------------------------------------------------------------+ Jun 26 '06 #6

### This discussion thread is closed

Replies have been disabled for this discussion.