QueueList - top() Library Question

Good day,

I have a question on QueueList.h Library found on http://playground.arduino.cc/Code/QueueList. The library consists of the followings methods:

void push (const T item)
//Push an item with data type “T” to the queue.
T pop ()
//Pop an item with data type “T” from the queue.
T peek ()
//Get an item with data type “T” from the queue.
bool isEmpty ()
//Check if the queue is empty.
int count ()
//Get the number of items in the queue.
void setPrinter (Print & printer)
//Sets the printer of the queue.

but…no top()?

Can anyone teach me how to write and include a top() function for the queue?

Thank you very much :blush:

#include <QueueList.h>

// declare string messages.
int msgA = 10;
int msgB = 20;
int msgD = 30;

// create a queue of strings messages.
QueueList queue;

// startup point entry (runs once).
setup () {
// start serial communication.
Serial.begin (9600);

// set the printer of the queue.
queue.setPrinter (Serial);

// push all the string messages to the queue.
queue.push (msgA);
queue.push (msgB);
queue.push (msgD);

// pop all the string messages from the queue.
queue.get the top value??
how do i get top value from the queue??

// loop the main sketch.
loop () {}

thanks if replied
thank you…

I’m not familiar with that library but if it has a push() method that I would say calling pop() or peek() will get you the last value pushed.

Or do you want the first value pushed? That is probably not possible without access to the internals of the class.

What exactly is the “top” of the queue?


@ school we defined the queue somewhat different: - push(elem) add element to queue - elem = pop() fetches the top element from queue - elem = top() copies the element in the top of the queue - elem = peek(i) copies element i from the queue - can be any element in the queue (if exists of course)

So I think top() the same as peek() is defined in the playGround class


Thanks for the replies. Because in C++ priority_queue the sql:top() actually exist to get the highest number in the queue. Therefore, i thought that QueueList library provided in Arduino would contain top() library. I still can't find the solution on how to get the highest value in the queue in arduino. I try max(x,y) but it only can be done if we know x and y value.

Thanks guys i will keep on trying.

Best regards. thanks

I still can’t find the solution on how to get the highest value in the queue in arduino.

A queue is to hold things to be processed in the order that they are added, like selling tickets to people in the order that they arrive at the ticket window.

A queue is completely the wrong sort of data structure to be using if you want to sell the next ticket to the tallest person waiting to buy a ticket.

That you seem to want to find the tallest person waiting to buy a ticket, perhaps you should explain why you are misusing a queue.


So if I read between your lines you want to have a priorityQueue and the ability to fetch the element with the highest value first .

same problem here…
I really need to implement a priority-queue on Arduino but there are not a solution… :confused:

but there are not a solution

Flex your fingers and start typing. Let us know when you are done.