You have already done everything, where r u stuck...about that swap logic?
well here is how it works,
suppose you have oil on bucket A
A=oil
and water in bucket B
B=water
, now you got to transfer oil to B and water to A,
final result B=oil, A=water
how will you do it?
Take another empty bucket C.
Put oil from A to C
C=A; (well in real world bucket A will get empty, but in programming, A and C both will have oil, ignore that and think this is real world)
Then,
Put the content of B(water) to A, so A contains water
A=B;
then put the content of C(oil) to B, so B contains Oil
B=C
This is how swap works.
For your problem
temp=list(i);
list(i)=list(i+1);
list(i+1)=temp;
Hope that explains .
Post your code, if therez logical or syntax error we can point it out. Java or C or C++?