How can I queue up in C ++ Builder? It is necessary to throw there the type values іnt, and then in the reverse order from there to get them.
1 answer
The classic answer is to use stl. There are ready-made solutions. Judging by the description, you need a stack. In any case, it can be arranged on the deck. Add #include <deque> now
std::deque<int> d; d.push_back(1); // добавить с конца d.push_front(2); // добавить с начала int x = d.back(); // взять с конца, но не удалять d.pop_back(); // и удалить int y = d.front(); // взять с начала d.pop_front(); // и удалить
That is, you can add and remove from the end you need (you can better imagine the deck as a pipe, from each end you can add and remove). More - here http://cplusplus.com/reference/stl/deque/
- oneAnd what std :: stack didn't please you? - dzhioev
- oneI initially thought of writing about it and about the queue, but I’m not sure if the stack or the queue is needed (I can’t vouch that I understand correctly "to get it in reverse order"). In addition, the stack is usually an adapter based on deque. - KoVadim pm
|