sorts an array using Selection sort