Created
June 22, 2012 00:49
-
-
Save aakashns/2969589 to your computer and use it in GitHub Desktop.
Backtracking Implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int finished = 0; /* found all solutions yet? */ | |
template <class T> | |
backtrack(int a[], int k, T * input) | |
{ | |
T c[MAXCANDIDATES]; /* candidates for next position */ | |
int ncandidates; /* next position candidate count */ | |
int i; /* counter */ | |
if (is_a_solution(a,k,input)) | |
process_solution(a,k,input); | |
else { | |
k = k+1; | |
construct_candidates(a,k,input,c,&ncandidates); | |
for (i=0; i<ncandidates; i++) { | |
a[k] = c[i]; | |
backtrack(a,k,input); | |
if (finished) return; /* terminate early */ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment