As amazing as this may sound, this is something you can actually write in approximately 20 lines of code. You can use a FOR loop inside of a recursive function to do most of the work. Use the FOR loop to break down a string into smaller sub-sections for each recursion. This example will hopefully give you an idea of what happens.
eg.
[abcd]
│
├ [a] - [bcd]
│
├┬ [ab] - [cd]
││
│├┬ [abc] - [d]
│││
││└─ [abcd] - [ ]
││
│└┬ [abd] - [c]
│ │
│ └─ [abdc] - [ ]
│
├ [b] - [acd]
│
Pay close attention to these two lines.
├ [a] - [bcd]
│
├┬ [ab] - [cd]
In the second string, [bcd], the first character, [b], is appended to the first string, [a]. In the next step,
├┬ [ab] - [cd]
││
│├┬ [abc] - [d]
the same thing occurs. In the last step,
│├┬ [abc] - [d]
│││
││└─ [abcd] - [ ]
the same thing occurs. However, this time the second string has no characters to add to the first string, so you would add the first string to an array or output it. In the next step,
├┬ [ab] - [cd]
││
│├┬
│││
││└─
││
│└┬ [abd] - [c]
you'll notice the second character of the second string is appended to the first string. This is where you want to use a FOR loop to cycle through the string. I'll leave it up to you on how to actually implement this. If you need any more help or are confused, send me an email.
2006-11-19 02:16:36
·
answer #1
·
answered by Kookiemon 6
·
1⤊
0⤋
If the string length isn't accepted beforehand, the only thank you to do it extremely is thru a recursive function. when you consider which you won't be able to apply purposes, you are able to write a software to jot down all mixtures of a a million, 2, 3, 4 and 5 character long strings. it's going to be something like this: char str[5]; scanf( "%d", str ); swap( len(string) ) : case a million: printf( "%d", str ); smash; case 2: // str is two characters long int i, j; for( i = 0; i < 2; i++ ) printf( "%d", str[i] ); for( j = 0; j < 2; j++ ) if( j != i ) { printf( %d n", str[ j ] ); } case 3: // str is 3 characters long int i, j, ok; etc...
2016-11-25 19:30:10
·
answer #2
·
answered by ? 4
·
0⤊
0⤋
could u explain your problem statement better...
2006-11-19 02:11:48
·
answer #3
·
answered by deostroll 3
·
0⤊
0⤋