Hi,
I checked your code, even executed the same and what I found was,
a change is needed in the swap code.
what you have written is :


int tmp = x[i] ;
x[i]=x[b] ;
x[b]= tmp ;