I have posted this question already on this forum here, but seeing as no one has answered I decided to try here.
Basically, I'm looking for a way to permute an array of integers given a range with no repeated permutations. I've had trouble understanding how to find permutations in the past, so I was hoping someone could give me an in-depth explaination of what I need to implement and why.
Here is my code as of now :
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define LENGTH 2 double NumberOfPermuationsOfString( int length, char minimum, char maximum ) { return pow( ( maximum - minimum ) + 1, length ); } int NextPermutation( char * buffer, char minimum, char maximum ) { const size_t length = strlen( buffer ) + 1; int i = 0; for ( ; i < length; ++i ) { /* I don't know what to do here... */ } return 0; } void DisplayPermutations( int length, char minimum, char maximum ) { char buffer[( length + 1 )]; memset( buffer, 0, sizeof( buffer ) ); memset( buffer, minimum, sizeof( buffer ) - 1 ); int i = 0; do { printf( "%s\n", buffer ); } while ( NextPermutation( &buffer[0], minimum, maximum ) ); } int main( ) { printf( "Iterating through %0.lf permuations...\n", NumberOfPermuationsOfString( LENGTH, 'a', 'z' ) ); DisplayPermutations( LENGTH, 'a', 'z' ); return 0; } THIS ISN'T C#, DON'T LET THE NAMING CONVENTION FOOL YOU...