• Stars
    star
    346
  • Rank 122,430 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created over 11 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔗 A fully implemented LinkedList made to work with general Microcontrollers and Arduino projects

LinkedList

This library was developed targeting Arduino applications. However, works just great with any C++.

Implementing a buffer for objects takes time. If we are not in the mood, we just create an array[1000] with enough size.

The objective of this library is to create a pattern for projects. If you need to use a List of: int, float, objects, Lists or Wales. This is what you are looking for.

With a simple but powerful caching algorithm, you can get subsequent objects much faster than usual. Tested without any problems with Lists bigger than 2000 members.

Installation

  1. Download the Latest release from gitHub.
  2. Unzip and modify the Folder name to "LinkedList" (Remove the '-version')
  3. Paste the modified folder on your Library folder (On your Libraries folder inside Sketchbooks or Arduino software).
  4. Reopen the Arduino software.

If you are here, because another Library requires this class, just don't waste time reading bellow. Install and ready.

Tests

cd to this directory and run g++ -std=c++14 extras/test/tests.cpp -o tests && ./tests


Getting started

The LinkedList class

In case you don't know what a LinkedList is and what it's used for, take a quick look at Wikipedia::LinkedList before continuing.

To declare a LinkedList object

// Instantiate a LinkedList that will hold 'integer'
LinkedList<int> myLinkedList = LinkedList<int>();

// Or just this
LinkedList<int> myLinkedList;

// But if you are instantiating a pointer LinkedList...
LinkedList<int> *myLinkedList = new LinkedList<int>();

// If you want a LinkedList with any other type such as 'MyClass'
// Make sure you call delete(MyClass) when you remove!
LinkedList<MyClass> *myLinkedList = new LinkedList<MyClass>();

Getting the size of the linked list

// To get the size of a linked list, make use of the size() method
int theSize = myList.size();

// Notice that if it's pointer to the linked list, you should use -> instead
int theSize = myList->size();

Adding elements

// add(obj) method will insert at the END of the list
myList.add(myObject);

// add(index, obj) method will try to insert the object at the specified index
myList.add(0, myObject); // Add at the beginning
myList.add(3, myObject); // Add at index 3

// unshift(obj) method will insert the object at the beginning
myList.unshift(myObject);

Getting elements

// get(index) will return the element at index
// (notice that the start element is 0, not 1)

// Get the FIRST element
myObject = myList.get(0);

// Get the third element
myObject = myList.get(2);

// Get the LAST element
myObject = myList.get(myList.size() - 1);

Changing elements

// set(index, obj) method will change the object at index to obj

// Change the first element to myObject
myList.set(0, myObject);

// Change the third element to myObject
myList.set(2, myObject);

// Change the LAST element of the list
myList.set(myList.size() - 1, myObject);

Deleting elements

// remove(index) will remove and return the element at index

// Remove the first object
myList.remove(0);

// Get and Delete the third element
myDeletedObject = myList.remove(2);

// pop() will remove and return the LAST element
myDeletedObject = myList.pop();

// shift() will remove and return the FIRST element
myDeletedObject = myList.shift();

// clear() will erase the entire list, leaving it with 0 elements
// NOTE: Clear wont DELETE/FREE memory from Pointers, if you
// are using Classes/Poiners, manualy delete and free those.
myList.clear();

Sorting elements

// Sort using a comparator function
myList.sort(myComparator);

Library Reference

ListNode struct

  • T ListNode::data - The object data

  • ListNode<T> *next - Pointer to the next Node

LinkedList class

boolean methods returns if succeeded

  • LinkedList<T>::LinkedList() - Constructor.

  • LinkedList<T>::~LinkedList() - Destructor. Clear Nodes to minimize memory. Does not free pointer memory.

  • int LinkedList<T>::size() - Returns the current size of the list.

  • bool LinkedList<T>::add(T) - Add element T at the END of the list.

  • bool LinkedList<T>::add(int index, T) - Add element T at index of the list.

  • bool LinkedList<T>::unshift(T) - Add element T at the BEGINNING of the list.

  • bool LinkedList<T>::set(int index, T) - Set the element at index to T.

  • T LinkedList<T>::remove(int index) - Remove element at index. Return the removed element. Does not free pointer memory

  • T LinkedList<T>::pop() - Remove the LAST element. Return the removed element.

  • T LinkedList<T>::shift() - Remove the FIRST element. Return the removed element.

  • T LinkedList<T>::get(int index) - Return the element at index.

  • void LinkedList<T>::clear() - Removes all elements. Does not free pointer memory.

  • void LinkedList<T>::sort(int (*cmp)(T &, T &)) - Sorts the linked list according to a comparator funcrion. The comparator should return < 0 if the first argument should be sorted before the second, and > 0 if the first argument should be sorted after the first element. (Same as how strcmp() works.)

  • protected int LinkedList<T>::_size - Holds the cached size of the list.

  • protected ListNode<T> LinkedList<T>::*root - Holds the root node of the list.

  • protected ListNode<T> LinkedList<T>::*last - Holds the last node of the list.

  • protected ListNode<T>* LinkedList<T>::getNode(int index) - Returns the index node of the list.

Version History

  • 1.1 (2013-07-20): Cache implemented. Getting subsequent objects is now O(N). Before, O(N^2).
  • 1.0 (2013-07-20): Original release

LinkedList

More Repositories

1

IAMDinosaur

🦄 An Artificial Inteligence to teach Google's Dinosaur to jump cactus
JavaScript
2,800
star
2

Is-Now-Illegal

🚫 A NERD protest against Trump's Immigration ban
JavaScript
1,372
star
3

node-draftlog

📜 Create mutable log lines into the terminal, and give life to your logs!
JavaScript
1,244
star
4

ArduinoThread

⏳ A simple way to run Threads on Arduino
C++
948
star
5

DueTimer

⏳ Timer Library fully implemented for Arduino DUE
C++
211
star
6

unicute

💙 Cute Unicode symbols. Make the terminal GREAT AGAIN
57
star
7

ArduinoSensors

A Library of Libraries of Sensors. Infrared, Ultrasonic, Compass and many others, ready to work with ArduinoThread and fully object oriented
C++
54
star
8

Gaussian

Library that makes Gaussian work easy to use with C++ and Arduino
C++
52
star
9

BigBang-js

Recreate the BigBang with JavaScript
JavaScript
48
star
10

Robot-Soccer-Simulator

⚽️ An Open-Source Soccer simulator for virtual robots tournaments
Java
34
star
11

EasyFly

A simple and just another Drone Firmware
C++
25
star
12

3DLiveView-ABB

Application using QT and native OpenGL, with a three based rendering engine to show a 3D ABB robot in sync with an arduino
C++
20
star
13

node-require-smart

The smart way of requiring multiple files in NodeJS
JavaScript
18
star
14

ABBNator

ABB Robots, playing TicTacToe with NodeJS in it's free time
JavaScript
16
star
15

Robot-Rescue-2013

RoboCup Junior Rescue B Robot sharing (CAD, Software, Electronics, materials and all stuff)
C
15
star
16

ArdUI

A generic, simple, easy to use User Interface for Arduino
C++
14
star
17

Robot-Soccer-2013

RoboCup Junior Soccer Robot sharing (CAD, Software, Electronics, materials and all stuff)
C
14
star
18

UTFT

A generic LCD Library for Arduino
C
11
star
19

Nao-Taokei

🚫Um app NERD para gerar gifs Huehue BR
JavaScript
6
star
20

NodePlate

Node boilerplate for servers
JavaScript
6
star
21

Robot-Rescue-2012

RoboCup Junior Rescue B Robot sharing (CAD, Software, Electronics, materials and all stuff)
Java
6
star
22

pcb-libraries

Place to keep and share special Altium, Eagle and Proteus components that we create and share with others.
6
star
23

oscilodrawer

Osciloscope Image drawer with Arduino and Nodejs MQTT
C++
5
star
24

Primo

Primo version using Stepper Motors and custom Software
C++
5
star
25

docker-node-python-opencv

A Dockerfile that installs Node.js, Python and OpenCV
4
star
26

tournamenter-obr

Extensão para o Tournamenter que permite pontuar pelo tablet em competições da OBR
JavaScript
4
star
27

easy-admin

Simple Admin UI with CRUD for Node.js
JavaScript
3
star
28

geddy-rest

REST Api made easy for Geddy
JavaScript
3
star
29

Robot-VerySmall-2015

Very Small Robot for 2015 CBR competition
Python
2
star
30

projetohangar

HTML
2
star
31

i23

An innovative way of connecting and communicating sensors with microcontrollers
2
star
32

node-ssl-vision

RoboCup SSL Vision Client library for Node.JS
JavaScript
2
star
33

Robot-Rescue-2011

Emerotecos Team's robot of Rescue A (OBR) 2011
HTML
1
star
34

Phyto-Gear

A simple Arduino robot that communicates with Facebook to notify that it's happy, sad, with or without light...
Arduino
1
star
35

TemPeixeNoRU

App de leitura de cardápio do RU da UFABC
1
star
36

Chenn

An real time graph as learning object for schools
JavaScript
1
star
37

rifa-generator

Projeto antigo de um Gerador de PDF's de Rifas
JavaScript
1
star
38

tournamenter-wro

Tournamenter Plugin for WRO - World Robotics Olympiad
JavaScript
1
star
39

robocup2014

Robocup 2014 Administration panel for leagues
JavaScript
1
star
40

NoFlow

A (really-simple) flow based programming framework
JavaScript
1
star