QueueList Library For Arduino

Author: Efstathios Chatzikyriakidis
Contact: contact@efxa.org

Library was updated for Arduino 1.0


Navigation


Current Version

1.0 2010-09-28 - Efstathios Chatzikyriakidis - added exit(), blink(): error reporting and handling methods.


History

1.0 2010-09-28 - Efstathios Chatzikyriakidis - added exit(), blink(): error reporting and handling methods.
1.0 2010-09-25 - Alexander Brevig - added setPrinter(): indirectly reference a Serial object.
1.0 2010-09-20 - Efstathios Chatzikyriakidis - initial release of the library.


Description

QueueList is a library implementing a generic, dynamic queue (linked list version) for the Arduino.

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

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


Installation

Download here: QueueList.zip

Put the "QueueList" directory in "libraries" directory.

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

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


Creation

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

QueueList <T> queue;

Create instance (object) of a QueueList class.


Methods

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

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.


Examples

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

/*
 *  Manage strings 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 <QueueList.h>

// declare string messages.
String msgA = "Happy Hacking!";
String msgB = "Hacking Happy!";

// create a queue of strings messages.
QueueList <String> queue;

// startup point entry (runs once).
void
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);

  // pop all the string messages from the queue.
  while (!queue.isEmpty ())
    Serial.println (queue.pop ());
}

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


FAQ

  • How do I use multiple queues?

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


Information

Last Modified: February 11, 2012, at 10:58 AM

By: efxa

Share