7 #ifndef AULA1_PROTECTEDLINKEDLIST_HPP 8 #define AULA1_PROTECTEDLINKEDLIST_HPP 32 return "Protected Linked List";
41 while (first != NULL) {
43 first = first->getNext();
55 if (index <=
size / 2) {
58 for (
int i = 0; i < index; i ++)
64 for (
int i = 0; i <
size - index; i ++)
65 tmp = tmp->getPrevious();
74 for (
int i = 0; i <= (
sizeof(data) /
sizeof(data[0])); i ++) {
96 virtual void insert(
const T val,
const int index) {
97 if (index < 0)
throw out_of_range(
"Negative index not allowed.");
99 if (index > size)
throw out_of_range(
"Nonexistent index.");
104 first->setValue(val);
113 else if (index == 0) {
117 first->setValue(val);
122 else if (index ==
size) {
132 Node<T> *previous = next->getPrevious();
137 middle->setValue(val);
139 middle->setNext(next);
140 next->setPrevious(middle);
142 middle->setPrevious(previous);
143 previous->setNext(middle);
152 if (index < 0)
throw out_of_range(
"Negative index not allowed.");
154 if (index >= size)
throw out_of_range(
"Nonexistent index in list.");
158 T ret = tmp->getValue();
160 if (tmp->getPrevious() != NULL)
161 tmp->getPrevious()->setNext(tmp->getNext());
163 first = tmp->getNext();
165 if (tmp->getNext() != NULL)
166 tmp->getNext()->setPrevious(tmp->getPrevious());
168 last = tmp->getPrevious();
173 tmp->setPrevious(NULL);
182 virtual T
get(
const int index) {
183 if (index < 0)
throw out_of_range(
"Negative index not allowed.");
185 if (index > size)
throw out_of_range(
"Nonexistent index.");
188 return tmp->getValue();
Node< T > * getLast() const
>>>>>>> master
Base class for all data structures.
bool isEmpty()
Check whether the structure is empty.
Node used inside other data structures.
bool isFull()
Check whether the structure is full.
virtual void insert(const T val, const int index)
Insert an element at the specified position in the list.
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
virtual Iterator< T > iterator()
Creates an Iterator, an object that allows the sequential access of values in a Linked List without t...
>>>>>>> bded2143692dca559ffcc9e7202d9eb5fbfc45bf
=======
virtual Iterator< T > iterator()
Creates an Iterator, an object that allows the sequential access of values in a Linked List without t...
>>>>>>> master
Node< T > * getFirst() const
Node< T > * getNode(int index)
Doubly-linked list implementation with dynamic memory allocation.
virtual T get(const int index)
Get the element at the specified position in the list, without removing.
string getName()
Provides the name of the data structure as a string representation.
virtual T remove(const int index)
Remove an element from the list.
Object that provides iterative powers to classes composed of Node.
ProtectedLinkedList(const T data[])
create the structure and populate it with the data from the array
virtual void insert(const T val)
Insert an element at the end of the list.
<<<<<<< HEAD
<<<<<<< HEAD
=======
virtual Iterator< T > iterator()
Creates an Iterator, an object that allows the sequential access of values in a Linked List without t...
Node< T > * getFirst() const
Node< T > * getNode(int index)
Doubly-linked list implementation with dynamic memory allocation.
virtual T get(const int index)
Get the element at the specified position in the list, without removing.
string getName()
Provides the name of the data structure as a string representation.
virtual T remove(const int index)
Remove an element from the list.
Object that provides iterative powers to classes composed of Node.
ProtectedLinkedList(const T data[])
create the structure and populate it with the data from the array
virtual void insert(const T val)
Insert an element at the end of the list.
int getSize()
Outputs the number of elements stored in the structure.
>>>>>>> 36f9b37... fixed dependency of ProtectedLinkedList to Iterator
=======
int getSize()
Outputs the number of elements stored in the structure.
>>>>>>> bded2143692dca559ffcc9e7202d9eb5fbfc45bf
=======
int getSize()
Outputs the number of elements stored in the structure.
>>>>>>> master