Linked List Class with Methods and Properties. More...
#include <linked_list.hpp>
Public Member Functions | |
| Linked_list () | |
| Constructor Creates an new empty Linked List object. | |
| Linked_list (std::vector< int > lst_values) | |
| Constructor Creates a linked list object from the values stored in the vector object. | |
| ~Linked_list () | |
| Destructor Removes all the nodes stored in the Linked list when the Linked List object is terminated. | |
| double | front () const |
| Method will return the value stored in the node at the front of the linked list (head node) if not empty. | |
| bool | empty () const |
| Method will return a boolean value indicating if the linked list is empty. | |
| void | push_front (int new_value) |
| Method will create a new node with the assigned value and placed it at the front of linked list. | |
| void | pop_front () |
| Method will remove the current head node and replace it with the next node in the list, if there is any. | |
| void | clear () |
| Method will clear all the nodes in the linked list, leaving an empty linked list object. | |
Friends | |
| std::ostream & | operator<< (std::ostream &out, Linked_list const &lst) |
| Allows this function to access the private member variables. | |
Linked List Class with Methods and Properties.
| Linked_list::Linked_list | ( | ) |
Constructor Creates an new empty Linked List object.
| Linked_list::Linked_list | ( | std::vector< int > | lst_values | ) |
Constructor Creates a linked list object from the values stored in the vector object.
Each value will be assigned a node, and all the nodes will form the linked list. The formation of the linked list object will maintain the same order as seen in the vector object.
| lst_values | The values to assign the nodes. |
| Linked_list::~Linked_list | ( | ) |
Destructor Removes all the nodes stored in the Linked list when the Linked List object is terminated.
| void Linked_list::clear | ( | ) |
Method will clear all the nodes in the linked list, leaving an empty linked list object.
| bool Linked_list::empty | ( | ) | const |
Method will return a boolean value indicating if the linked list is empty.
| double Linked_list::front | ( | ) | const |
Method will return the value stored in the node at the front of the linked list (head node) if not empty.
Otherwise, it will throw an Out of Range Error
| void Linked_list::pop_front | ( | ) |
Method will remove the current head node and replace it with the next node in the list, if there is any.
If the linked list is empty, nothing will happen
| void Linked_list::push_front | ( | int | new_value | ) |
Method will create a new node with the assigned value and placed it at the front of linked list.
| new_value | The value of the node you want to assign as the new head node |
|
friend |
Allows this function to access the private member variables.
| out | The output data |
| lst | The Linked list object |