implement permute by sorting example