Pergunta de entrevista da empresa Google

Write code that sorts a stack

Respostas da entrevista

Sigiloso

19 de jun. de 2014

You use another stack to help with the sorting

1

Sigiloso

10 de set. de 2014

Or just use recursion(implicit stack).

Sigiloso

5 de jan. de 2015

Pop everything into a sorted map/tree?

Sigiloso

17 de fev. de 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); } }