diff options
add non const front & back
1 files changed, 19 insertions, 0 deletions
| -rw-r--r-- | Seminar05/LinkedList.hpp | 19 |
diff --git a/Seminar05/LinkedList.hpp b/Seminar05/LinkedList.hpp index 1281a43..58f8794 100644 --- a/Seminar05/LinkedList.hpp +++ b/Seminar05/LinkedList.hpp @@ -129,6 +129,9 @@ public: const T& front() const; const T& back() const; + T& front(); + T& back(); + bool empty() const; size_t size() const; @@ -292,6 +295,14 @@ const T& LinkedList<T>::front() const { } template<class T> +T& LinkedList<T>::front() { + if(empty()) + throw std::runtime_error("Empty list!"); + + return head->data; +} + +template<class T> const T& LinkedList<T>::back() const { if(empty()) throw std::runtime_error("Empty list!"); @@ -300,6 +311,14 @@ const T& LinkedList<T>::back() const { } template<class T> +T& LinkedList<T>::back() { + if(empty()) + throw std::runtime_error("Empty list!"); + + return tail->data; +} + +template<class T> LinkedList<T>::~LinkedList() { free(); } |
