deck
array in ascending order.deck.length - 1
.result
of the same length as deck
to store the final ordering.deck
, do the following:
a. Pop the front index from the queue and place the current card at that index in the result
array.
b. If the queue is not empty, pop the next index from the front and push it to the back of the queue.result
array.