From 46b9e6f61275c4ed4cd2e8f319cad4f6bc73100f Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 31 Jan 2020 12:46:19 +0100 Subject: List split cpp hpp (may be ridiculous and may have forgot how templates work) --- List.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 List.cpp (limited to 'List.cpp') 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; +} -- cgit