I am making a c++ program and i need a function that does the following:
IF u have an n (e.g: 4) digit number (IN THE FORM OF AN ARRAY) , each digit can take the vlaue from 0 to m (e.g: 5) and can exist more than once in the number (EACH DIGIT IS AN ELEMENT IN THE ARRAY)..
The number starts by the minimum value that the digits can form...
The number enters in a loop which increases the number, every iteration, to generate the NEXT BIGGER number that consists of the same digits and prints the number...
NOTE::: I dont want the function to increase the number every time by ONE and checks that the digits are there.... this will be silly :p... I asked this question to find the fastest algorithm ....
Thanks in advance :)
so what you're trying to do is create a sorting algorithm that, through each pass, will create a number that was bigger than the previous number specified.
I believe this is what you mean--
// before function call
[0][0][1][2][3]
// after one function call
[0][0][1][3][2]
//after two calls
[0][0][2][1][3]
//after three calls
[0][0][2][3][1]
// after four calls
[0][0][3][1][2]
// after five calls
[0][0][3][2][1]
// after six calls
[0][1][0][2][3]
//after seven calls
[0][1][0][3][2]
// after eight calls
[0][1][2][0][3]
// after nine calls
[0][1][2][3][0]
// after ten calls
[0][1][3][0][2]
// after eleven calls
[0][1][3][2][0]
//after twelve calls
[0][2][0][1][3]
//...
Is this the correct logic?