Pregunta de entrevista de Apple

sorting algorithm for complicated queue