5. Implement Queue using ForwardList interface

5. Implement Queue<T> using ForwardList<T> interface#

Complete the following tasks using the ForwardList provided below,

  1. Implement Queue1<T> using ForwardList<T> by privately inheritance.

  2. Implement Queue2<T> using ForwardList<T> by composition.

  3. Define a function template that consumes (get and pop element) all elements of the queue and print them out. After that, explicitly instantiate it with Queue1<char> and specialize it with Queue2<int>.

forward_list.hpp#
 1#ifndef FORWARD_LIST_HPP
 2#define FORWARD_LIST_HPP
 3
 4template <typename T>
 5struct Node {
 6 public:
 7  Node* next = nullptr;
 8  T data;
 9};
10
11template <typename T>
12class ForwardList {
13 public:
14  ForwardList();
15
16  int size() const;
17  bool empty() const;
18  T const& front() const;
19  T const& back() const;
20  void remove(Node<T> const* value);
21  void push_front(T const& value);
22  void push_back(T const& value);
23
24  // Returns the first element that equals to value in the range [start_position, list_last_node]
25  // - If `start_position == nullptr`, the range is [list_first_node, list_last_node]
26  // - Returns nullptr if no such element is found
27  Node<T> const* find(Node<T> const* start_position, T const& value) const;
28};
29
30#endif