aboutsummaryrefslogtreecommitdiff
path: root/list.hpp
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-11-19 01:51:38 +0100
committerCharles <sircharlesaze@gmail.com>2019-11-19 02:40:38 +0100
commitf89b202792c118a0baa5fb7f4978dbc2077b64d4 (patch)
treee205c23ca8cb490122beda2d58a28b4361f08eb7 /list.hpp
parentfebf0637f9869419bc5864543c89e3fd0b1ac316 (diff)
downloadft_containers-f89b202792c118a0baa5fb7f4978dbc2077b64d4.tar.gz
ft_containers-f89b202792c118a0baa5fb7f4978dbc2077b64d4.tar.bz2
ft_containers-f89b202792c118a0baa5fb7f4978dbc2077b64d4.zip
basic stack and list
Diffstat (limited to 'list.hpp')
-rw-r--r--list.hpp74
1 files changed, 70 insertions, 4 deletions
diff --git a/list.hpp b/list.hpp
index aaff3e8..c8645b4 100644
--- a/list.hpp
+++ b/list.hpp
@@ -1,12 +1,78 @@
#ifndef LIST_HPP
# define LIST_HPP
-template < class T, class Alloc = allocator<T> >
-class list
+namespace ft
{
+ template < class T, class Alloc = allocator<T> >
+ class list
+ {
+ public:
+ bool empty() const
+ {
+ return front == nullptr;
+ }
+ size_type size() const
+ {
+ return size;
+ }
+ reference front()
+ {
+ return *front;
+ }
+ reference back()
+ {
+ return *back;
+ }
+ void push_front (const value_type& val)
+ {
+ t_inner_list *nfront = new t_inner_list;
+ nfront->content = val;
+ nfront->next = front;
+ front = nfront;
+ if (back == nullptr)
+ back = front;
+ size++;
+ }
+ void pop_front()
+ {
+ t_inner_list *nfront = front->next;
+ if (nfront == nullptr)
+ back = nullptr;
+ ~T(front->content);
+ delete front;
+ front = nfront;
+ size--;
+ }
+ void push_back (const value_type& val)
+ {
+ t_inner_list *nback = new t_inner_list;
+ nback->content = val;
+ if (back == nullptr)
+ {
+ back = nback;
+ front = back;
+ return;
+ }
+ back->next = nback;
+ back = nback;
+ size++;
+ }
+ void pop_back()
+ {
- t_list *head;
-};
+ }
+
+ private:
+ typedef struct
+ {
+ t_inner_list *next;
+ T content;
+ } t_inner_list;
+ t_inner_list *front;
+ t_inner_list *back;
+ size_type size;
+ };
+}
#endif