-
Notifications
You must be signed in to change notification settings - Fork 1
/
LinkedList.h
76 lines (66 loc) · 1.85 KB
/
LinkedList.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
LinkedList.h - V1.1 - Generic LinkedList implementation
Works better with FIFO, because LIFO will need to
search the entire List to find the last one;
For instructions, go to https://github.com/ivanseidel/LinkedList
Created by Ivan Seidel Gomes, March, 2013.
Released into the public domain.
*/
#ifndef LinkedList_h
#define LinkedList_h
#include <Arduino.h>
template<class T>
struct ListNode
{
T data;
ListNode<T> *next;
};
template <typename T>
class LinkedList{
protected:
int _size;
ListNode<T> *root;
ListNode<T> *last;
// Helps "get" method, by saving last position
ListNode<T> *lastNodeGot;
int lastIndexGot;
// isCached should be set to FALSE
// everytime the list suffer changes
bool isCached;
ListNode<T>* getNode(int id);
public:
LinkedList();
~LinkedList();
/* Returns current size of LinkedList */
virtual int size();
/* Adds a T object in the specified index;
Unlink and link the LinkedList correcly;
Increment _size */
virtual bool add(int index, T);
/* Adds a T object in the end of the LinkedList;
Increment _size; */
virtual bool add(T);
/* Adds a T object in the start of the LinkedList;
Increment _size; */
virtual bool unshift(T);
/* Set the object at index, with T;
Increment _size; */
virtual bool set(int index, T);
/* Remove object at index;
If index is not reachable, returns false;
else, decrement _size */
virtual T remove(int index);
/* Remove last object; */
virtual T pop();
/* Remove first object; */
virtual T shift();
/* Get the index'th element on the list;
Return Element if accessible,
else, return false; */
virtual T get(int index);
/* Clear the entire array */
virtual void clear();
virtual ListNode<T>* getRoot();
};
#include "LinkedList.cpp"
#endif