Convert some Python code to C++
meyousikmann at yahoo.com
meyousikmann at yahoo.com
Tue Nov 13 10:28:49 EST 2007
I am working on an implementation of the Longest Common Subsequence
problem (as I understand it, this problem can be used in spell
checking type activities) and have used this site to understand the
problem and its solution:
http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Longest_common_subsequence
For those that understand algorithms and can talk Python, I want to
convert the Python code in the section "Reading out all LCSs" into C++
code but I don't understand some of the syntax. Can anyone give me a
hand?
Here is the code from that section, but is probably of little use
without understanding the entire problem setup given at the site
above:
def backTrackAll(C, X, Y, i, j):
if i == 0 or j == 0:
return set([""])
elif X[i-1] == Y[j-1]:
return set([Z + X[i-1] for Z in backTrackAll(C, X, Y, i-1,
j-1)])
else:
R = set()
if C[i][j-1] >= C[i-1][j]:
R.update(backTrackAll(C, X, Y, i, j-1))
if C[i-1][j] >= C[i][j-1]:
R.update(backTrackAll(C, X, Y, i-1, j))
return R
Thanks!
More information about the Python-list
mailing list