This class expands on the previous linked list class by including a pointer to the list tail. This allows us to implement more functionality but also requires us to update any member functions that modified the linkked list.
class Linked_list {
public:
Linked_list(); // Constructor
~Linked_list(); // Destructor
bool empty() const;
std::size_t size() const;
double front() const;
double back() const;
std::string to_string() const;
std::size_t find( double const value ) const;
double operator[]( std::size_t const n ) const;
void push_front( double const new_value );
void push_back( double const new_value );
Linked_list &operator+=( Linked_list const &list ) const;
void pop_front();
void clear();
private:
Node *p_list_head_; // Pointer to head node
Node *p_list_tail_; // Pointer to tail node
std:size_t size_; // Number of nodes in the linked list
};
View this simple linked list at repl.it.
The class declarations and definitions are in the corresponding Linked_list.hpp file.