Question d’entretien chez Google

Write code that sorts a stack

Réponses aux questions d'entretien

Utilisateur anonyme

19 juin 2014

You use another stack to help with the sorting

1

Utilisateur anonyme

10 sept. 2014

Or just use recursion(implicit stack).

Utilisateur anonyme

5 janv. 2015

Pop everything into a sorted map/tree?

Utilisateur anonyme

17 févr. 2018

Using the same queue, do "bubble sort" length(queue) times: void bubbleSortQueue(std::queue* toSort ) { int length = toSort->size(); if (length front(); toSort->pop(); for (int currItem = 0; currItem front(); toSort->pop(); if (first > second) { toSort->push(second); } else { toSort->push(first); first = second; } } toSort->push(first); } }