swapElements function

Swap the position of two elements in a grid.