{"id":13781377,"url":"https://github.com/ivanseidel/LinkedList","last_synced_at":"2025-05-11T14:35:01.312Z","repository":{"id":9626026,"uuid":"11554573","full_name":"ivanseidel/LinkedList","owner":"ivanseidel","description":"🔗 A fully implemented LinkedList made to work with general Microcontrollers and Arduino projects","archived":false,"fork":false,"pushed_at":"2024-06-21T13:57:28.000Z","size":56,"stargazers_count":353,"open_issues_count":20,"forks_count":118,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-18T21:26:21.586Z","etag":null,"topics":["arduino","arduino-library","linkedlist","mbed"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ivanseidel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-20T23:35:28.000Z","updated_at":"2025-03-05T19:15:53.000Z","dependencies_parsed_at":"2024-08-03T18:22:35.236Z","dependency_job_id":null,"html_url":"https://github.com/ivanseidel/LinkedList","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanseidel%2FLinkedList","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanseidel%2FLinkedList/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanseidel%2FLinkedList/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanseidel%2FLinkedList/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivanseidel","download_url":"https://codeload.github.com/ivanseidel/LinkedList/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253580381,"owners_count":21930933,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","arduino-library","linkedlist","mbed"],"created_at":"2024-08-03T18:01:25.413Z","updated_at":"2025-05-11T14:35:01.066Z","avatar_url":"https://github.com/ivanseidel.png","language":"C++","readme":"# LinkedList\n\nThis library was developed targeting **`Arduino`** applications. However, works just great with any C++.\n\nImplementing a buffer for objects takes time. If we are not in the mood, we just create an `array[1000]` with enough size.\n\nThe objective of this library is to create a pattern for projects.\nIf you need to use a List of: `int`, `float`, `objects`, `Lists` or `Wales`. **This is what you are looking for.**\n\nWith 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.\n\n## Installation\n\n1. [Download](https://github.com/ivanseidel/LinkedList/archive/master.zip) the Latest release from gitHub.\n2. Unzip and modify the Folder name to \"LinkedList\" (Remove the '-version')\n3. Paste the modified folder on your Library folder (On your `Libraries` folder inside Sketchbooks or Arduino software).\n4. Reopen the Arduino software.\n\n**If you are here, because another Library requires this class, just don't waste time reading bellow. Install and ready.**\n\n## Tests\n\n`cd` to this directory and run `g++ -std=c++14 extras/test/tests.cpp -o tests \u0026\u0026 ./tests`\n\n-------------------------\n\n## Getting started\n\n### The `LinkedList` class\n\nIn case you don't know what a LinkedList is and what it's used for, take a quick look at [Wikipedia::LinkedList](https://en.wikipedia.org/wiki/Linked_list) before continuing.\n\n#### To declare a LinkedList object\n```c++\n// Instantiate a LinkedList that will hold 'integer'\nLinkedList\u003cint\u003e myLinkedList = LinkedList\u003cint\u003e();\n\n// Or just this\nLinkedList\u003cint\u003e myLinkedList;\n\n// But if you are instantiating a pointer LinkedList...\nLinkedList\u003cint\u003e *myLinkedList = new LinkedList\u003cint\u003e();\n\n// If you want a LinkedList with any other type such as 'MyClass'\n// Make sure you call delete(MyClass) when you remove!\nLinkedList\u003cMyClass\u003e *myLinkedList = new LinkedList\u003cMyClass\u003e();\n```\n\n#### Getting the size of the linked list\n```c++\n// To get the size of a linked list, make use of the size() method\nint theSize = myList.size();\n\n// Notice that if it's pointer to the linked list, you should use -\u003e instead\nint theSize = myList-\u003esize();\n```\n\n#### Adding elements\n\n```c++\n// add(obj) method will insert at the END of the list\nmyList.add(myObject);\n\n// add(index, obj) method will try to insert the object at the specified index\nmyList.add(0, myObject); // Add at the beginning\nmyList.add(3, myObject); // Add at index 3\n\n// unshift(obj) method will insert the object at the beginning\nmyList.unshift(myObject);\n```\n\n#### Getting elements\n\n```c++\n// get(index) will return the element at index\n// (notice that the start element is 0, not 1)\n\n// Get the FIRST element\nmyObject = myList.get(0);\n\n// Get the third element\nmyObject = myList.get(2);\n\n// Get the LAST element\nmyObject = myList.get(myList.size() - 1);\n```\n\n#### Changing elements\n```c++\n// set(index, obj) method will change the object at index to obj\n\n// Change the first element to myObject\nmyList.set(0, myObject);\n\n// Change the third element to myObject\nmyList.set(2, myObject);\n\n// Change the LAST element of the list\nmyList.set(myList.size() - 1, myObject);\n```\n\n#### Deleting elements\n```c++\n// remove(index) will remove and return the element at index\n\n// Remove the first object\nmyList.remove(0);\n\n// Get and Delete the third element\nmyDeletedObject = myList.remove(2);\n\n// pop() will remove and return the LAST element\nmyDeletedObject = myList.pop();\n\n// shift() will remove and return the FIRST element\nmyDeletedObject = myList.shift();\n\n// clear() will erase the entire list, leaving it with 0 elements\n// NOTE: Clear wont DELETE/FREE memory from Pointers, if you\n// are using Classes/Poiners, manualy delete and free those.\nmyList.clear();\n```\n\n#### Sorting elements\n```c++\n// Sort using a comparator function\nmyList.sort(myComparator);\n```\n\n------------------------\n\n## Library Reference\n\n### `ListNode` struct\n\n- `T` `ListNode::data` - The object data\n\n- `ListNode\u003cT\u003e` `*next` - Pointer to the next Node\n\n### `LinkedList` class\n\n**`boolean` methods returns if succeeded**\n\n- `LinkedList\u003cT\u003e::LinkedList()` - Constructor.\n\n- `LinkedList\u003cT\u003e::~LinkedList()` - Destructor. Clear Nodes to minimize memory. Does not free pointer memory.\n\n- `int` `LinkedList\u003cT\u003e::size()` - Returns the current size of the list.\n\n- `bool` `LinkedList\u003cT\u003e::add(T)` - Add element T at the END of the list.\n\n- `bool` `LinkedList\u003cT\u003e::add(int index, T)` - Add element T at `index` of the list.\n\n- `bool` `LinkedList\u003cT\u003e::unshift(T)` - Add element T at the BEGINNING of the list.\n\n- `bool` `LinkedList\u003cT\u003e::set(int index, T)` - Set the element at `index` to T.\n\n- `T` `LinkedList\u003cT\u003e::remove(int index)` - Remove element at `index`. Return the removed element. Does not free pointer memory\n\n- `T` `LinkedList\u003cT\u003e::pop()` - Remove the LAST element. Return the removed element.\n\n- `T` `LinkedList\u003cT\u003e::shift()` - Remove the FIRST element. Return the removed element.\n\n- `T` `LinkedList\u003cT\u003e::get(int index)` - Return the element at `index`.\n\n- `void` `LinkedList\u003cT\u003e::clear()` - Removes all elements. Does not free pointer memory.\n\n- `void` `LinkedList\u003cT\u003e::sort(int (*cmp)(T \u0026, T \u0026))` - Sorts the linked list according to a comparator funcrion. The comparator should return \u003c 0 if the first argument should be sorted before the second, and \u003e 0 if the first argument should be sorted after the first element. (Same as how `strcmp()` works.)\n\n- **protected** `int` `LinkedList\u003cT\u003e::_size` - Holds the cached size of the list.\n\n- **protected** `ListNode\u003cT\u003e` `LinkedList\u003cT\u003e::*root` - Holds the root node of the list.\n\n- **protected** `ListNode\u003cT\u003e` `LinkedList\u003cT\u003e::*last` - Holds the last node of the list.\n\n- **protected** `ListNode\u003cT\u003e*` `LinkedList\u003cT\u003e::getNode(int index)` - Returns the `index` node of the list.\n\n### Version History\n\n* `1.1 (2013-07-20)`: Cache implemented. Getting subsequent objects is now O(N). Before, O(N^2).\n* `1.0 (2013-07-20)`: Original release\n\n![LinkedList](https://d2weczhvl823v0.cloudfront.net/ivanseidel/LinkedList/trend.png)\n","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanseidel%2FLinkedList","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivanseidel%2FLinkedList","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanseidel%2FLinkedList/lists"}