i need code [message #92376] |
Fri, 18 June 2004 12:15 |
Hind
Messages: 6 Registered: October 2000
|
Junior Member |
|
|
i realy do need to now how to write the code of the next two algorithms as soon as posible for a deadly need in java would be better :
Algorithm 1 : Permutation of {1,...,n}
First permutation is given by xi = i for i=1,...,n
next permutation after (x1,...,xn) :
- Find the largest j for which xj < xj+1 (working back from the end ).
- If no such j exist, then the curent permutation is the last .
- Interchange the value of xj with the least xk greater than xj with k>j then reverse the seqence of values of xj+1,...,xn ;
return this permutation
Algorithm 2 : Partial permutation of {1,...,n}
Fisrt partial permutaion is the empty sequence.
Next object after (x1,...,xm) :
-If the lenght m of the current sequence is less than n, extend it by adjoining the least element it doesn't contain.
-Otherwise ,proceed as in the algorithm for permutaion, up to the point where xj and xk interchanged; then , instead of reversing the terms after xj, remove them from seqence.
and i'll be thankful
|
|
|