user31867: Does anyone know if there is a way to create a queue of some sort for arduino?
My project consists of simulating multiple traffic lights with crossing pedestrians on an Arduino breadboard. Since I need to assume the situation where on all sides are cars waiting + pedestrians having pressed the button, I needed to figure out a way to store these inputs into an array of some sort.
However, the problem with array I believe is that it doesn't allow me to shift the data to the left, so that the next one will be selected in the queue. Deleting the data inside an array would only merely make it null, which doesn't work.
Greatly appreciated if someone can help me by pointing to the right direction.

user3917: Regarding how to “create a queue of some sort for Arduino”, about the first thing to settle is how many items may need to be queued.  On a typical personal computer with gigabytes of RAM, queue size often is not much of an issue ... one just allocates a few more megabytes whenever necessary.  On an typical Arduino, however, with a few kilobytes or few tens of kilobytes of RAM, use of dynamic (heap) allocation is risky unless you carefully analyze possible execution paths.
If you are ok with a fixed queue size, the next issue is what kind of queue, eg FIFO, LIFO, priority, etc.  The question's concern about a “shift the data to the left, so that the next one will be selected in the queue” issue suggests a FIFO (first in first out) queue is desired.  For this, a circular buffer or circular queue is a relatively-low-overhead method often used.  Using terms from the wikipedia article, Start and End pointers are maintained, marking next-data-out and last-data-in positions.  Via modular arithmetic or if tests, each of these pointers wraps to array front whenever it goes past the array end.   The queue is empty if Start == End (modulo N, if queue size is N) and full if Start == End+1.  
If an interrupt-driven process can modify pointers asynchronously to the main thread of execution, then synchronization methods need to be used to ensure atomic updates of pointers.  (This is true for all kinds of queues, not just circular ones.)
If instead of a FIFO queue you need a priority queue, a binary heap is easy to implement. Usually Fibonacci heaps and binomial heaps are not worth the extra trouble of implementing, except when you need efficient heap merging or secondary operations like decreasing keys of elements.  The Summary of running times section of wikipedia's binomial heap article shows the complexity of different operations across different heap structures.  Note that with Arduino RAM being so limited, a complexity difference like Θ(log n) vs Θ(1) is negligible; simplicity of code, leading to a compact implementation, is more important.
Note, also see QueueList Library For Arduino at arduino.cc.  This library apparently uses dynamic allocation.  It provides methods push(), pop(), peek() et al.  Also see QueueArray Library For Arduino at arduino.cc, which provides the same methods as QueueList, plus enqueue and dequeue() as synonyms for push() and pop().  Where QueueList uses lists to build its data structures, QueueArray uses arrays.
OsWrap at arduino.cc is a heavy package (eg 15KB flash, 1.5KB RAM) that supports various message and priority queue structures.
Depending on your rationale for using a queue, Task Scheduler Library may also be of interest.
As noted in Mikael Patel's comments above, Cosa platform software includes a Queue class, which is a “Template class for ring-buffer for queueing data elements”, with usage of the class illustrated in an Event class, which in turn is used in a Job class.

user31802: I wrote a simple queue library some weeks ago, you can find it in the arduino library manager, or here:
Queue
I think you need FIFO implementation, but LIFO is also implemented in the lib & possibility to overwrite previous records when full.
It can handle any structure or data type (as long as it's size is fixed for memory allocation), defining a number of records in the queue, then you're good to go.
2 methods are implemented to interact with the queue, push() & pull().
I'll probably add a peek() later on if needed.
I also noticed this other FIFO only queue lib in the library manager when I commited mine: MD_CirQueue
Hope this can help!

31867: <p>Does anyone know if there is a way to create a queue of some sort for arduino?</p>

<p>My project consists of simulating multiple traffic lights with crossing pedestrians on an Arduino breadboard. Since I need to assume the situation where on all sides are cars waiting + pedestrians having pressed the button, I needed to figure out a way to store these inputs into an array of some sort.</p>

<p>However, the problem with array I believe is that it doesn't allow me to shift the data to the left, so that the next one will be selected in the queue. Deleting the data inside an array would only merely make it null, which doesn't work.</p>

<p>Greatly appreciated if someone can help me by pointing to the right direction.</p>
 3917: <p>Regarding how to “create a queue of some sort for Arduino”, about the first thing to settle is how many items may need to be queued.  On a typical personal computer with gigabytes of RAM, queue size often is not much of an issue ... one just allocates a few more megabytes whenever necessary.  On an typical Arduino, however, with a few kilobytes or few tens of kilobytes of RAM, use of dynamic (heap) allocation is risky unless you carefully analyze possible execution paths.</p>

<p>If you are ok with a fixed queue size, the next issue is what kind of queue, eg FIFO, LIFO, priority, etc.  The question's concern about a “shift the data to the left, so that the next one will be selected in the queue” issue suggests a FIFO (first in first out) queue is desired.  For this, a <a href="https://en.wikipedia.org/wiki/Circular_buffer" rel="nofollow noreferrer">circular buffer or circular queue</a> is a relatively-low-overhead method often used.  Using terms from the wikipedia article, Start and End pointers are maintained, marking next-data-out and last-data-in positions.  Via modular arithmetic or <code>if</code> tests, each of these pointers wraps to array front whenever it goes past the array end.   The queue is empty if <code>Start == End</code> (modulo N, if queue size is N) and full if <code>Start == End+1</code>.  </p>

<p>If an interrupt-driven process can modify pointers asynchronously to the main thread of execution, then synchronization methods need to be used to ensure atomic updates of pointers.  (This is true for all kinds of queues, not just circular ones.)</p>

<p>If instead of a FIFO queue you need a priority queue, a <a href="https://en.wikipedia.org/wiki/Binary_heap" rel="nofollow noreferrer">binary heap</a> is easy to implement. Usually <a href="https://en.wikipedia.org/wiki/Fibonacci_heap" rel="nofollow noreferrer">Fibonacci heaps</a> and <a href="https://en.wikipedia.org/wiki/Binomial_heap" rel="nofollow noreferrer">binomial heaps</a> are not worth the extra trouble of implementing, except when you need efficient heap merging or secondary operations like decreasing keys of elements.  The <a href="https://en.wikipedia.org/wiki/Binomial_heap#Summary_of_running_times" rel="nofollow noreferrer">Summary of running times</a> section of wikipedia's binomial heap article shows the complexity of different operations across different heap structures.  Note that with Arduino RAM being so limited, a complexity difference like Θ(log n) vs Θ(1) is negligible; simplicity of code, leading to a compact implementation, is more important.</p>

<p>Note, also see <a href="http://playground.arduino.cc/Code/QueueList" rel="nofollow noreferrer"><em>QueueList Library For Arduino</em></a> at arduino.cc.  This library apparently uses dynamic allocation.  It provides methods <code>push(), pop(), peek()</code> et al.  Also see <a href="http://playground.arduino.cc/Code/QueueArray" rel="nofollow noreferrer"><em>QueueArray Library For Arduino</em></a> at arduino.cc, which provides the same methods as <em>QueueList</em>, plus <code>enqueue</code> and <code>dequeue()</code> as synonyms for <code>push()</code> and <code>pop()</code>.  Where <em>QueueList</em> uses lists to build its data structures, <em>QueueArray</em> uses arrays.</p>

<p><a href="http://playground.arduino.cc/Code/OsWrap" rel="nofollow noreferrer"><em>OsWrap</em> at arduino.cc</a> is a heavy package (eg 15KB flash, 1.5KB RAM) that supports various message and priority queue structures.</p>

<p>Depending on your rationale for using a queue, <a href="http://playground.arduino.cc/Code/TaskScheduler" rel="nofollow noreferrer"><em>Task Scheduler Library</em></a> may also be of interest.</p>

<p>As noted in Mikael Patel's comments above, <a href="https://github.com/mikaelpatel/Cosa" rel="nofollow noreferrer">Cosa</a> platform software includes a <a href="https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Queue.hh" rel="nofollow noreferrer">Queue</a> class, which is a “Template class for ring-buffer for queueing data elements”, with usage of the class illustrated in an <a href="https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Event.hh" rel="nofollow noreferrer">Event</a> class, which in turn is used in a <a href="https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Job.hh" rel="nofollow noreferrer">Job</a> class.</p>
 31802: <p>I wrote a simple queue library some weeks ago, you can find it in the arduino library manager, or here:
<a href="https://github.com/SMFSW/Queue" rel="nofollow noreferrer">Queue</a></p>

<p>I think you need FIFO implementation, but LIFO is also implemented in the lib &amp; possibility to overwrite previous records when full.<br>
It can handle any structure or data type (as long as it's size is fixed for memory allocation), defining a number of records in the queue, then you're good to go.</p>

<p>2 methods are implemented to interact with the queue, push() &amp; pull().
I'll probably add a peek() later on if needed.</p>

<p>I also noticed this other FIFO only queue lib in the library manager when I commited mine: <a href="https://github.com/MajicDesigns/MD_CirQueue" rel="nofollow noreferrer">MD_CirQueue</a></p>

<p>Hope this can help!</p>
