Data Structures in C++
DynamicQueue.hpp
Go to the documentation of this file.
1 /**
2  * @author Douglas De Rizzo Meneghetti (douglasrizzom@gmail.com)
3  * @date 2017-6-14
4  * @brief Queue implementation with dynamic memory allocation
5  */
6 #ifndef AULA1_DYNAMICQUEUE_HPP
7 #define AULA1_DYNAMICQUEUE_HPP
8 
9 #include <stdexcept>
10 #include <iostream>
11 #include "Queue.hpp"
13 
14 //! Queue implementation with dynamic memory allocation.
15 //! This queue extends a ProtectedLinkedList in order to gain dynamic memory allocation powers.
16 //! \tparam T The type of object the data structure will contain
17 template<class T>
18 class DynamicQueue : public ProtectedLinkedList<T>, public Queue<T> {
19  public:
20  string getName() { return "Dynamic Queue"; }
21 
22  explicit DynamicQueue() {}
23 
24  //! create the structure and populate it with the data from the array
25  //! \param data an array with data with which the structure will be initialized
26  explicit DynamicQueue(int data[]) : ProtectedLinkedList<T>(data) {}
27 
28  void enqueue(T val) {
29  ProtectedLinkedList<T>::insert(val, ProtectedLinkedList<T>::getSize());
30  }
31 
32  T dequeue() {
33  if (isEmpty())
34  throw std::out_of_range("The queue is empty");
35  return ProtectedLinkedList<T>::remove(0);
36  }
37 
38  T peek() {
39  if (isEmpty())
40  throw std::out_of_range("The queue is empty");
41  return ProtectedLinkedList<T>::get(0);
42  }
43 
44  int getSize() { return ProtectedLinkedList<T>::getSize(); }
45 
46  bool isEmpty() { return ProtectedLinkedList<T>::isEmpty(); }
47 
48  bool isFull() { return ProtectedLinkedList<T>::isFull(); }
49 };
50 
51 #endif
void enqueue(T val)
Add an element to the end of the queue.
Queue implementation with dynamic memory allocation.
bool isEmpty()
Check whether the structure is empty.
Abstract queue interface.
Definition: Queue.hpp:16
T dequeue()
Remove an element from the queue.
<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD
bool isFull()
Check whether the structure is full.
======= >>>>>>> 36f9b37... fixed dependency of ProtectedLinkedList to Iterator ======= >>>>>>> bded2143692dca559ffcc9e7202d9eb5fbfc45bf ======= >>>>>>> master
int getSize()
Outputs the number of elements stored in the structure.
bool isFull()
Check whether the structure is full.
Doubly-linked list implementation with dynamic memory allocation.
DynamicQueue(int data[])
create the structure and populate it with the data from the array
T peek()
See the first value from the queue, without removing it.
string getName()
Provides the name of the data structure as a string representation.