Recursive permutation method using lists

Hey,

I am having difficulties writing a recursive method that displays all permutations of a list. It has to be recursive and not iterative and it has to take in a list<int>. I can write the method using a string parameter or making it iterative, but I can't for the life of me (i've been sitting here for the past 8 hours) write it recursively so that it takes in a list and displays all possible permutations.

Here is what I have so far:

iLst routeData::bestRoute(iLst done, iSet left)
{
iSetPtr setIterator;
for(setIterator = left.begin(); setIterator != left.end(); setIterator++)
{
iLst tempList = done;
iSet tempSet = left;

tempList.push_back(*setIterator);
tempSet.erase(setIterator);
bestRoute(tempList, tempSet);
}


return done;
}

It starts with the parameters {1} and {2, 3, 4} for example.
[988 byte] By [nbakewell] at [2007-11-20 11:46:47]
# 1 Re: Recursive permutation method using lists
You could try like this (in pseudocode):

getPermutations(list)
if list is one element
return a new list with list inside (a list of lists)

permutes = new list (this will be a list of lists)
for i in list
subPermutes = getPermutations(list without i)

for p in subPermutes
l = new list with only i in it
put concat l and p in permutes
return permutes

This is a very simple version, you'll have to expand it a fair bit to convert it to C++ but this is the jist of it.
IllegalCharacter at 2007-11-9 1:26:14 >