aboutsummaryrefslogtreecommitdiff
path: root/List.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'List.cpp')
-rw-r--r--List.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/List.cpp b/List.cpp
new file mode 100644
index 0000000..f88ca36
--- /dev/null
+++ b/List.cpp
@@ -0,0 +1,89 @@
+#include "List.hpp"
+
+ft::List::List(const allocator_type& alloc = allocator_type())
+{
+ front = nullptr;
+ back = nullptr;
+ size = 0;
+
+}
+
+ft::List::~List()
+{
+ while (size > 0)
+ pop_front();
+}
+
+ft::List::bool empty() const
+{
+ return front == nullptr;
+}
+ft::List::size_type size() const
+{
+ return size;
+}
+
+ft::List::reference front()
+{
+ return *front;
+}
+
+ft::List::reference back()
+{
+ return *back;
+}
+
+ft::List::void push_front (const value_type& val)
+{
+ PrivateList *nfront = new PrivateList(val);
+ nfront->next = front;
+ front = nfront;
+ if (back == nullptr)
+ back = front;
+ size++;
+}
+
+ft::List::void pop_front()
+{
+ t_llist *nfront = front->next;
+ if (size == 1)
+ back = nullptr;
+ delete front;
+ front = nfront;
+ size--;
+}
+
+ft::List::void push_back (const value_type& val)
+{
+ PrivateList *nback = new PrivateList(val);
+ if (empty())
+ {
+ back = nback;
+ front = back;
+ return;
+ }
+ back->next = nback;
+ back = nback;
+ size++;
+}
+
+ft::List::void pop_back()
+{
+ t_llist *tmp = front;
+
+ while (tmp->next != back)
+ tmp = tmp->next;
+ delete back;
+ back = tmp;
+}
+
+ft::List::PrivateList::PrivateList(const value_type& val);
+{
+ next = nullptr;
+ val = val;
+}
+
+ft::List::PrivateList::~PrivateList()
+{
+ delete val;
+}