2010-09-29, 06:38 PM
talked to a teachers assistant, got the permutation done, trying to get the same function to get the best value for the various permutations.
is what i have right now. The RecursivePermute function keeps forgetting what the new bestScore is though, meaning if i initialize it to 0, it will put it back to 0 each time it recurses, which is how I want it to do it at first, but I wanted it to test if the sum was higher, and if it was make it the new best score. Which it does, and prints that out, but the next iteration reduces bestScore back to 0. Can anyone see what im doing wrong?
Code:
void RecursivePermute(int *str, int k, int len, int **weakLink, int bestScore) {
int j, i, q, a, b;
int sum;
int Person;
if (k == len){
sum = 0;
for(i=0; i<len; i++){
Person= str[i];
sum = sum + weakLink[i][Person];
}
printf("%d\n", sum);
if (sum>bestScore){
bestScore= sum;
}
printf("Best : %d\n", bestScore);
}
else {
for (j=k; j<len; j++) {
Exchange(str, k, j);
RecursivePermute(str, k+1, len, weakLink, bestScore);
Exchange(str, j, k);
}
}
}
void Exchange(int *str, int i, int j) {
int temp = str[i];
str[i] = str[j];
str[j] = temp;
}is what i have right now. The RecursivePermute function keeps forgetting what the new bestScore is though, meaning if i initialize it to 0, it will put it back to 0 each time it recurses, which is how I want it to do it at first, but I wanted it to test if the sum was higher, and if it was make it the new best score. Which it does, and prints that out, but the next iteration reduces bestScore back to 0. Can anyone see what im doing wrong?

