Data Structures in C++
LinkedList.hpp
Go to the documentation of this file.
1 /**
2  * @author Douglas De Rizzo Meneghetti (douglasrizzom@gmail.com)
3  * @date 2017-6-8
4  * @brief Doubly-linked list implementation with dynamic memory allocation
5  */
6 
7 #ifndef AULA1_LINKEDLIST_HPP
8 #define AULA1_LINKEDLIST_HPP
9 
10 #include <iostream>
12 
13 //! Doubly-linked list implementation with dynamic memory allocation.
14 //! This class exposes many of the protected methods from ProtectedLinkedList, where all list-related functionality is actually implemented.
15 //! \tparam T The type of object the data structure will contain
16 template<class T>
17 class LinkedList : public ProtectedLinkedList<T> {
18  public:
19  explicit LinkedList() {
20  }
21 
22  //! create the structure and populate it with the data from the array
23  //! \param data an array with data with which the structure will be initialized
24  explicit LinkedList(T data[]) : ProtectedLinkedList<T>(data) {
25  }
26 
27  string getName() { return "Linked List"; }
28 
29  //! Insert an element at the end of the list
30  //! \param val the value to be inserted
31  virtual void insert(T val) {
32  ProtectedLinkedList<T>::insert(val);
33  }
34 
35  //! Insert an element at the specified position in the list
36  //! \param val the value to be inserted
37  //! \param index position of the list that the element will be inserted on
38  virtual void insert(T val, int index) {
39  ProtectedLinkedList<T>::insert(val, index);
40  }
41 
42  //! Remove an element from the list
43  //! \param index position of the element to be removed
44  //! \return the element that is being removed
45  virtual T remove(int index) {
46  return ProtectedLinkedList<T>::remove(index);
47  }
48 
49  //! Get the element at the specified position in the list, without removing it
50  //! \param index index of the desired element
51  virtual T get(int index) {
52  return ProtectedLinkedList<T>::get(index);
53  }
54 
55  //! Creates an Iterator, an object that allows the sequential
56  //! access of values in a Linked List without the search overhead
57  //! \return an Iterator starting from the first node of the list
59  return Iterator<T>(ProtectedLinkedList<T>::getFirst());
60  }
61 };
62 
63 #endif
virtual void insert(T val)
Insert an element at the end of the list.
Definition: LinkedList.hpp:31
Doubly-linked list implementation with dynamic memory allocation.
Definition: LinkedList.hpp:17
Iterator< T > iterator()
Creates an Iterator, an object that allows the sequential access of values in a Linked List without t...
Definition: LinkedList.hpp:58
<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD
bool isFull()
Check whether the structure is full.
=======
Doubly-linked list implementation with dynamic memory allocation.
>>>>>>> 36f9b37... fixed dependency of ProtectedLinkedList to Iterator =======
Doubly-linked list implementation with dynamic memory allocation.
>>>>>>> bded2143692dca559ffcc9e7202d9eb5fbfc45bf =======
Doubly-linked list implementation with dynamic memory allocation.
>>>>>>> master
virtual T get(int index)
Get the element at the specified position in the list, without removing it.
Definition: LinkedList.hpp:51
virtual void insert(T val, int index)
Insert an element at the specified position in the list.
Definition: LinkedList.hpp:38
Object that provides iterative powers to classes composed of Node.
Definition: Iterator.hpp:13
LinkedList(T data[])
create the structure and populate it with the data from the array
Definition: LinkedList.hpp:24
string getName()
Provides the name of the data structure as a string representation.
Definition: LinkedList.hpp:27
virtual T remove(int index)
Remove an element from the list.
Definition: LinkedList.hpp:45