QT C++ DATA Structures
-
wrote on 4 Aug 2022, 14:11 last edited by
How to access any element of stack or queue without pop() operation in c++ ?
-
wrote on 5 Aug 2022, 05:54 last edited by JonB 8 May 2022, 06:55
@ELIF
Then why not say so from the start?! So your question is not connected to Qt C++ datastricturesstructures after all. You can see the methods ofstd::queue
from the docs:The std::queue class is a container adaptor that gives the programmer the functionality of a queue - specifically, a FIFO (first-in, first-out) data structure.
The class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The queue pushes the elements on the back of the underlying container and pops them from the front.
Accessors are
front()
andback()
It's a queue. So you cannot access middling elements, and why would you want to if you are choosing to use a queue?However, @JoeCFD's
std::dequeue
does allow access to middling elements. See Access c++ queue elements like an array for a discussion. -
wrote on 4 Aug 2022, 14:28 last edited by
I will use queue.
-
wrote on 4 Aug 2022, 14:48 last edited by
std::deque may be a better option.
-
wrote on 5 Aug 2022, 05:54 last edited by JonB 8 May 2022, 06:55
@ELIF
Then why not say so from the start?! So your question is not connected to Qt C++ datastricturesstructures after all. You can see the methods ofstd::queue
from the docs:The std::queue class is a container adaptor that gives the programmer the functionality of a queue - specifically, a FIFO (first-in, first-out) data structure.
The class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The queue pushes the elements on the back of the underlying container and pops them from the front.
Accessors are
front()
andback()
It's a queue. So you cannot access middling elements, and why would you want to if you are choosing to use a queue?However, @JoeCFD's
std::dequeue
does allow access to middling elements. See Access c++ queue elements like an array for a discussion. -
wrote on 5 Aug 2022, 06:26 last edited by
1/8