Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit7fbf4ea0b5679b83e637006b48ca1a287ebf3302 (patch)
Author
 Stoycho Kyosev <stoycho.kk@gmail.com>
2022-11-12 18:37:07 +0200
Committer
 Stoycho Kyosev <stoycho.kk@gmail.com>
2022-11-12 18:37:07 +0200
Files0a303767f1404bc9b9600c03dd32265aaa542a92
Data-structures-and-algorithms-7fbf4ea0b5679b83e637006b48ca1a287ebf3302.tar
Data-structures-and-algorithms-7fbf4ea0b5679b83e637006b48ca1a287ebf3302.tar.gz
Data-structures-and-algorithms-7fbf4ea0b5679b83e637006b48ca1a287ebf3302.zip
Parente51e5e5fdb8fed6969aa6f608663fac9c4ac8bba (diff)
add non const front & back
1 files changed, 19 insertions, 0 deletions
-rw-r--r--Seminar05/LinkedList.hpp19
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();
}