Sort a nearly sorted (or K sorted) array