diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-31 12:46:19 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-31 12:46:19 +0100 |
| commit | 46b9e6f61275c4ed4cd2e8f319cad4f6bc73100f (patch) | |
| tree | c33522b5337b0214154232870eaa830b3f0e4108 /List.cpp | |
| parent | f89b202792c118a0baa5fb7f4978dbc2077b64d4 (diff) | |
| download | ft_containers-46b9e6f61275c4ed4cd2e8f319cad4f6bc73100f.tar.gz ft_containers-46b9e6f61275c4ed4cd2e8f319cad4f6bc73100f.tar.bz2 ft_containers-46b9e6f61275c4ed4cd2e8f319cad4f6bc73100f.zip | |
List split cpp hpp (may be ridiculous and may have forgot how templates work)
Diffstat (limited to 'List.cpp')
| -rw-r--r-- | List.cpp | 89 |
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; +} |
