A simple, templated linked list implementation for Arduino projects. This class allows you to create and manage a linked list of any data type.
- Templated class: Can store any data type.
- Dynamic resizing: Automatically manages memory as elements are added or removed.
- Basic operations:
append
,prepend
,insert
,remove
,get
,contains
,getSize
,isEmpty
,clear
.
WARNING: This Library Utilizes POINTERS *. This is due to the Libraries ability to utilize any return type. (Bool, String, int, float, etc)
To use LinkedList
in your Arduino sketch:
- Copy the
LinkedList
class code to your project's directory. - Include
LinkedList.h
at the top of your sketch.
- Initial Release
- Fixed an issue with the getElement() Function. The function will return the item if its found, or it will return a default constructed T() in the event an item is not found.
==================================================================
- Initial Release
- Fixed Issues Related to Library Not Building.
- Syntax Errors that were not discovered originally when Library was update have not been rectified. Library Should now work as intended.
- Update to README
- Added [LINKED LIST]: to the Serial Print Statements to make it easier to debug
- Added Overloaded Insert Function() to insert a value at a specific index
- Added Insert Function to insert a value randomly into the list
- Adjusted size Variable to be capitalized as Size. That way the compiler will not get confused with the size() function
- Added an Iterator to the LinkedList. This will allow you to iterate through the list
- This Library Has been partially tested. Please report any bugs to the Author
- Added a boolean variable to the LinkedList Constructor to determine if the LinkedList should print to the Serial Monitor or not.
- Added a setDebug() function to set the debug variable to true or false
- Added a getDebug() function to get the debug variable
- Added a new function called getAsString() to return the LinkedList element as a String
- Deprecated the keyExists() and valueExists() functions. They will be removed in the next release.. (Use contains() instead)
- Removed debug statements from the library, this is to save memory. A duplicate Library will be created with debug statements in it.
- Added Function Comments to the Library
- REMOVING Two Deprecated Functions -> Use contains()
- Renamed the remove function to more closely correlate to what it does.
- Added new remove function that takes in an index to remove to match other List Libraries.
- Added getElement Function that returns the element instead of the pointer to the element.
- Renaming Linked List Files (including src File) to BasicLinkedList. This is due to Arduino Library Manager Requiring Library Headers to Match Library Names. And since you cannot Duplicate Library Names, The library will be Listed the same as PlatformIO. (BasicLinkedList)
- Fixed an issue with the getElement() Function. The function will return the item if its found, or it will return a default constructed T() in the event an item is not found.
cpp insert(1 parameter version) prepend() append() size() get()
prepend, and append were used automatically by the insert function
To create a linked list, simply declare an instance of LinkedList
with the desired type:
#include <LinkedList.h>
LinkedList<int> myList;
myList.append(1);
myList.prepend(0);
myList.insert(2, 1); // Insert '2' at position '1'
myList.insert(1); //Insert '1' anywhere in the List.
int value = myList.get(1);
myList.remove(1);
if (myList.contains(2)) {
// Element is in the list
}
size_t size = myList.size();
if (myList.isEmpty()) {
// List is empty
}
myList.clear();
LinkedList<int> myList;
myList.append(1);
myList.append(2);
myList.prepend(0);
myList.insert(3, 3);
for (size_t i = 0; i < myList.size(); i++) {
Serial.print("Element at position ");
Serial.print(i);
Serial.print(": ");
Serial.println(myList.get(i));
}
myList.remove(2);
myList.clear();