All Projects → ivanseidel → Linkedlist

ivanseidel / Linkedlist

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

Projects that are alternatives of or similar to Linkedlist

Corsairlightingprotocol
Control LEDs connected to an Arduino with iCUE, create an unofficial Corsair iCUE compatible Arduino LED controller.
Stars: ✭ 182 (-24.48%)
Mutual labels:  arduino, arduino-library
Helios
The free embedded operating system.
Stars: ✭ 223 (-7.47%)
Mutual labels:  arduino, arduino-library
Duetimer
⏳ Timer Library fully implemented for Arduino DUE
Stars: ✭ 184 (-23.65%)
Mutual labels:  arduino, arduino-library
Arduinowebsockets
A library for writing modern websockets applications with Arduino (ESP8266 and ESP32)
Stars: ✭ 213 (-11.62%)
Mutual labels:  arduino, arduino-library
Dsckeybusinterface
An Arduino/esp8266/esp32 library to directly interface with DSC security systems.
Stars: ✭ 202 (-16.18%)
Mutual labels:  arduino, arduino-library
Acebutton
An adjustable, compact, event-driven button library for Arduino that debounces and dispatches events to a user-defined event handler.
Stars: ✭ 180 (-25.31%)
Mutual labels:  arduino, arduino-library
Easybutton
Arduino library for debouncing momentary contact switches, detect press, release, long press and sequences with event definitions and callbacks.
Stars: ✭ 187 (-22.41%)
Mutual labels:  arduino, arduino-library
Bh1750
An Arduino library for the digital light sensor breakout boards containing the BH1750FVI IC
Stars: ✭ 173 (-28.22%)
Mutual labels:  arduino, arduino-library
Radio
An Arduino library to control FM radio chips like SI4703, SI4705, RDA5807M, TEA5767.
Stars: ✭ 193 (-19.92%)
Mutual labels:  arduino, arduino-library
Teensystep
Fast Stepper Motor Library for Teensy boards
Stars: ✭ 191 (-20.75%)
Mutual labels:  arduino, arduino-library
Arduino Applemidi Library
Send and receive MIDI messages over Ethernet (rtpMIDI or AppleMIDI)
Stars: ✭ 177 (-26.56%)
Mutual labels:  arduino, arduino-library
Arduino Tvout
Arduino-TVout
Stars: ✭ 216 (-10.37%)
Mutual labels:  arduino, arduino-library
Packetserial
An Arduino Library that facilitates packet-based serial communication using COBS or SLIP encoding.
Stars: ✭ 177 (-26.56%)
Mutual labels:  arduino, arduino-library
Esp32 Ble Mouse
Bluetooth LE Mouse library for the ESP32 (Arduino IDE compatible)
Stars: ✭ 180 (-25.31%)
Mutual labels:  arduino, arduino-library
M5stack Sd Updater
💾 Customizable menu system for M5Stack and ESP32-Chimera-Core - loads apps from the Micro SD card. Easily add you own apps
Stars: ✭ 175 (-27.39%)
Mutual labels:  arduino, arduino-library
Md max72xx
LED Matrix Library
Stars: ✭ 186 (-22.82%)
Mutual labels:  arduino, arduino-library
Espmqttclient
Wifi and MQTT handling for ESP8266 and ESP32
Stars: ✭ 169 (-29.88%)
Mutual labels:  arduino, arduino-library
Socket.io Client
A socket.io-client implementation for ESP8266 and Arduino
Stars: ✭ 170 (-29.46%)
Mutual labels:  arduino, arduino-library
Dmxserial
An Arduino library for sending and receiving DMX packets.
Stars: ✭ 190 (-21.16%)
Mutual labels:  arduino, arduino-library
Timezone
Arduino library to facilitate time zone conversions and automatic daylight saving (summer) time adjustments.
Stars: ✭ 205 (-14.94%)
Mutual labels:  arduino, arduino-library

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 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);

Removing 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].