Recursion-Move all x at end

Please tell the mistakes in the code.