I can't find simple example how to use queues in C++ for pointers to some myclass objects. I have code like this:
class myclass{ string s; }; myclass *p = new myclass(); my_queue.push(p); //something.... p = my_queue.front(); my_queue.pop(); std::cout << p->s;
What should be declaration of my_queue? Should I use queue or another data structure?
I need c++ just for small program, thanks for answers.
A queue in C is basically a linear data structure to store and manipulate the data elements. It follows the order of First In First Out (FIFO). In queues, the first element entered into the array is the first element to be removed from the array. For example, let's consider the scenario of a bus-ticket booking stall.
Simple Queue A simple queue is the most basic queue. In this queue, the enqueue operation takes place at the rear, while the dequeue operation takes place at the front: Its applications are process scheduling, disk scheduling, memory management, IO buffer, pipes, call center phone systems, and interrupt handling.
Examples of queues in "real life": A ticket line; An escalator; A car wash.
Simply declare it as below if you want to us the STL queue container.
std::queue<myclass*> my_queue;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With