Implemented algorithm that uses element swapping.