aboutsummaryrefslogtreecommitdiff
path: root/week13/Exercise2/Vector.hpp
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2024-05-25 16:08:17 +0300
committerSyndamia <kamen@syndamia.com>2024-05-25 16:08:17 +0300
commit9c11fababb9b6b194e646fbeb62d141aacf74c43 (patch)
treef1a294fcd66b22463b9424c838ff171db8539a15 /week13/Exercise2/Vector.hpp
parentc6fae5f1a0cc8394b1de3b671f07de7b3d677c59 (diff)
downloadoop-2023-solutions-9c11fababb9b6b194e646fbeb62d141aacf74c43.tar
oop-2023-solutions-9c11fababb9b6b194e646fbeb62d141aacf74c43.tar.gz
oop-2023-solutions-9c11fababb9b6b194e646fbeb62d141aacf74c43.zip
[w13] Added solutions
Diffstat (limited to 'week13/Exercise2/Vector.hpp')
-rw-r--r--week13/Exercise2/Vector.hpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/week13/Exercise2/Vector.hpp b/week13/Exercise2/Vector.hpp
new file mode 100644
index 0000000..ba66049
--- /dev/null
+++ b/week13/Exercise2/Vector.hpp
@@ -0,0 +1,35 @@
+#pragma once
+#include "Indexable.hpp"
+#include "Resizeable.hpp"
+
+template <class T>
+class Vector : public Indexable<T>, public Resizeable<T> {
+public:
+ void pop_back();
+ void pop_front();
+ void push_back(const T& element);
+ void push_front(const T& element);
+};
+
+template <class T>
+void Vector<T>::pop_back() {
+ this->size--;
+}
+
+template <class T>
+void Vector<T>::pop_front() {
+ for (int i = 0; i < this->size - 1; i++) {
+ this->arr[i] = this->arr[i+1];
+ }
+ this->size--;
+}
+
+template <class T>
+void Vector<T>::push_back(const T& element) {
+ this->InsertAt(this->size - 1, element);
+}
+
+template <class T>
+void Vector<T>::push_front(const T& element) {
+ this->InsertAt(0, element);
+}