Advanced Programming II, Spring 2004

Programming Assignment 2 - An Example Solution


It was at this point that I made a mistake that one of your colleagues caught. I had originally assumed that the last permutation generated would be the same as the initial permutation, and wrote the loop as

for (unsigned m = mid; m < perm.size(); m++)
  std::swap(perm[mid], perm[m])
  permulate(perm, mid + 1, strs, r)

Becuase my (stupid, as I now see) assumption was wrong, my code might select the same list item several times, which generated identical permutations and didn't generate other permutations.


This page last modified on 25 March 2004.