Re: permutation function problem



On Jun 29, 7:19 pm, "Wade Ward" <inva...@xxxxxxxxxxxx> wrote:
"tiger66" <liuallen1...@xxxxxxxxx> wrote in message

news:1183144766.352345.115410@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



Hi All
I am trying to create a permutation function. I found the
implementation online, but the implementation uses for() loop in the
main() and it has the List as a parameter. All I am trying to do is to
modify the implementation, so that all the loops are in the function
and the parameter is a char array instead of a list.
public static <T> List<T> permute(List<T> list, int r) {
int n= list.size();
int f= fac(n);
: List<T> perm= new ArrayList<T>();

okay, I will check out the books

but why doesn't my code work? I really want to find to solution to
this problem

Thanks

list= new ArrayList<T>(list);
for (list= new ArrayList<T>(list); n > 0; n--, r%= f) {

f/= n;
perm.add(list.remove(r/f));
}

return perm;

}

Check out TAOCP from the library. What does the above do?
--
Wade Ward


.



Relevant Pages

  • Re: permutation function problem
    ... I am trying to create a permutation function. ... implementation online, but the implementation uses forloop in the ... int n= list.size; ...
    (comp.programming)
  • Re: permutation function problem
    ... I am trying to create a permutation function. ... implementation online, but the implementation uses forloop in the ... int n= list.size; ...
    (comp.programming)
  • Re: Fridays the thirteenth. (And a little puzzle.)
    ... -- compiler) is the usual method ... int febdays ... -- We're going to go round a loop dealing with each year in turn. ... -- other languages call) ...
    (uk.people.silversurfers)
  • Re: C code is not generating required results.
    ... int main ... the array by the size of an element. ... prevent the user of your program from entering more characters than ... want to loop. ...
    (comp.lang.c)
  • Re: long double versions of functions in gcc under Cygwin
    ... rather than the nearest enclosing one) and a decent exception ... them it doesn't seem like goto usage would be affected ... int typfun() ... Why use a for loop when it is just a while loop in disguise? ...
    (comp.lang.c)