Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ queue - simple example

Tags:

c++

queue

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.

like image 354
Ondra Avatar asked Jan 04 '11 11:01

Ondra


People also ask

What is queue in C with example?

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.

What is simple queue with example?

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.

What is queue real life example?

Examples of queues in "real life": A ticket line; An escalator; A car wash.


1 Answers

Simply declare it as below if you want to us the STL queue container.

std::queue<myclass*> my_queue; 
like image 157
Nim Avatar answered Sep 30 '22 17:09

Nim