That is close, but examine what happens when you swap two elements. The value of the first element is overwritten, by the time you assign it a new value.
E.G. Let x(i) be 5, and x(j) be 6.
x(i) becomes x(j) = 6
x(j) becomes x(i) = 6 as well
The solution to this is to use a temporary variable, let's say
temp, to remember the first value, before the swapping occurs.
temp = x(i)
x(i) = x(j)
x(j) = temp