QueueArray Library For Arduino

Author: Efstathios Chatzikyriakidis
Contact: contact@efxa.org

Library was updated for Arduino 1.0


Navigation


Current Version

1.0 2014-02-03 - Brian Fletcher - added enqueue(), dequeue() and front().


History

1.0 2014-02-03 - Brian Fletcher - added enqueue(), dequeue() and front().
1.0 2010-09-29 - Efstathios Chatzikyriakidis - added resize(): for growing, shrinking the array size.
1.0 2010-09-25 - Efstathios Chatzikyriakidis - added exit(), blink(): error reporting and handling methods.
1.0 2010-09-24 - Alexander Brevig - added setPrinter(): indirectly reference a Serial object.
1.0 2010-09-20 - Efstathios Chatzikyriakidis - initial release of the library.


Description

QueueArray is a library implementing a generic, dynamic queue (array version) for the Arduino.

It is created to help adding FIFO (First In - First Out) Abstract Data Structure to a program for any use.

QueueArray library is part of the "Data Structures & Algorithms" libraries.


Installation

Download here: QueueArray.zip

Put the "QueueArray" directory in "libraries" directory.

In the Arduino IDE, create a new sketch and select from the menubar "Sketch->Import Library->QueueArray".

Once the library is imported, an "#include <QueueArray.h>" line will appear at the top of your Sketch.


Creation

Replace "T" with the data type you want to use.

QueueArray <T> queue;

Create instance (object) of a QueueArray class.


Methods

Replace "T" with the data type you want to use.

void enqueue (const T item)

Put an item with data type "T" to the queue.

T dequeue ()

Take an item with data type "T" from the front of the queue and remove it.

T front ()

Take an item with data type "T" from the front of the queue but do not remove it.

void push (const T item)

Same as enqueue.

T pop ()

Same as dequeue.

T peek ()

Same as front.

bool isEmpty ()

Check if the queue is empty.

bool isFull ()

Check if the queue is full.

int count ()

Get the number of items in the queue.

void setPrinter (Print & printer)

Sets the printer of the queue.


Examples

Manage a string by using a generic, dynamic queue data structure.

/*
 *  Manage a string by using a generic, dynamic queue data structure.
 *
 *  Copyright (C) 2010  Efstathios Chatzikyriakidis (contact@efxa.org)
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
 */


// include queue library header.
#include <QueueArray.h>

// declare a string message.
const String msg = "Happy Hacking!";

// create a queue of characters.
QueueArray <char> queue;

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

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

  // enqueue all the message's characters to the queue.
  for (int i = 0; i < msg.length (); i++)
    queue.enqueue (msg.charAt (i));

  // dequeue all the message's characters from the queue.
  while (!queue.isEmpty ())
    Serial.print (queue.dequeue ());

  // print end of line character.
  Serial.println ();
}

// loop the main sketch.
void
loop () {
  // nothing here.
}


FAQ

  • How do I use multiple queues?

QueueArray is a class. Therefore to use multiple queues, you must create an instance for each of them.


Information

Last Modified: February 03, 2014, at 06:16 PM

By: bfletcher

Share