# getting all possible ordering of vector

• 01-08-2010, 10:47 PM
sara12345
getting all possible ordering of vector
hello
I need to find all possible order of a set of vector I mean if I have the following:
0
1
2
all posssible would be:
0 1 2, 1 0 2, 2 1 0, 1 2 0, 2 0 1, 0 2 1

I have tried to use the swap but I didn't get all possible set
I have used the following code:
Code:

```for( int x=0;x<vector.size();x++)        {                 for ( int w=0;w< vector.size();w++){ Collections.swap(vector, x, w);}}```
as I said before the swap method didn't provide me the result I want
can somebody tell me how to do it please urgent
• 01-08-2010, 10:59 PM
pbrockway2
If you stop and think about it there are size! different orderings, but you are only doing size^2 swaps, so that was never going to work.

This seems to be an extension of your thread http://www.java-forums.org/new-java/...ts-vector.html. You're welcome, but couldn't you have explained there what you were trying to do? (the problem apparently is not redundancy but, rather, that you aren't doing enough swaps).

Consider recursion.
• 01-08-2010, 11:03 PM
sara12345
sorry! you are right after runing the program I have found that the swap is not the solution to my problem because I want to find all possible ordering set of vector and then try to order the elements of vector according to some critriea. but as I said the swap doesn't solve my problem because it doesn't find all possible ordering set. if you know how can I solve my problem please tell me
thanks
• 01-08-2010, 11:21 PM
pbrockway2