| Author |
Johnson Trotter Algorithm help
|
Hunter McMillen
Ranch Hand
Joined: Mar 13, 2009
Posts: 490
|
|
**Overview:**
I am trying to implement the Johnson Trotter Algorithm in Java so that I can solve a problem on Project Euler. I have looked and looked but as far as I can see I have everything implemented right, which you know is wrong, otherwise I wouldn't be asking this question
The basic algorithm goes like this:
I have created an `Element` object that has attributes to use for this algorithm. When I am swapping values, only one swap occurs, then after that the original order is printed over and over.
**Code:**
**Expectations:**
I would expect the algorithm to do something like this
Start:
<0 <1 <2
<0 <2 <1
<2 <0 <1
etc
**Actual**
This is what it actually does
Start:
<0 <1 <2
<0 <2 <1
<2 <0 <1
<2 <0 <1
it doesnt change after the second swap
Any help would be awesome, also if you have comments/pointers about my style those would also be much appreciated, Thanks.
Sorry for long post.
PS - Also posted on SO: http://stackoverflow.com/questions/6877504/johnson-trotter-algorithm
|
"If the facts don't fit the theory, get new facts" --Albert Einstein
|
 |
Hunter McMillen
Ranch Hand
Joined: Mar 13, 2009
Posts: 490
|
|
Someone on SO found my problem, I will post the solution after I have made the necessary changes
Hunter
|
 |
Hunter McMillen
Ranch Hand
Joined: Mar 13, 2009
Posts: 490
|
|
Sorry it has taken so long, this is the solution I came up with using the Johnson Trotter algorithm, if anyone is interested. Any feedback on my code would be appreciated.
Thanks
|
 |
 |
|
|
subject: Johnson Trotter Algorithm help
|
|
|