aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-31 12:46:19 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-31 12:46:19 +0100
commit46b9e6f61275c4ed4cd2e8f319cad4f6bc73100f (patch)
treec33522b5337b0214154232870eaa830b3f0e4108
parentf89b202792c118a0baa5fb7f4978dbc2077b64d4 (diff)
downloadft_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)
-rw-r--r--List.cpp89
-rw-r--r--List.hpp95
-rw-r--r--README.md2
-rw-r--r--Stack.htpp (renamed from stack.hpp)0
-rw-r--r--Vector.hpp (renamed from vector.hpp)0
-rw-r--r--list.hpp78
6 files changed, 185 insertions, 79 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;
+}
diff --git a/List.hpp b/List.hpp
new file mode 100644
index 0000000..57a9a8f
--- /dev/null
+++ b/List.hpp
@@ -0,0 +1,95 @@
+#ifndef LIST_HPP
+# define LIST_HPP
+
+namespace ft
+{
+ template < class T, class Alloc = allocator<T> >
+ class List
+ {
+ public:
+ List(const allocator_type& alloc = allocator_type());
+ // List(size_type n, const value_type& val = value_type(), const allocator_type& alloc = allocator_type());
+ // template <class InputIterator>
+ // List(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type());
+ // List(const list& x);
+ ~List();
+ // List& operator = (const List& x);
+
+ // iterators
+ // iterator begin();
+ // const_iterator begin() const;
+ // iterator end();
+ // const_iterator end() const;
+ // reverse_iterator rbegin();
+ // const_reverse_iterator rbegin() const;
+ // reverse_iterator rend();
+ // const_reverse_iterator rend() const;
+
+ // capacity
+ bool empty() const;
+ size_type size() const;
+ size_type max_size() const;
+
+ // element access
+ reference front();
+ const_reference front() const;
+ reference back();
+ const_reference back();
+
+ // modifiers
+ // template <class InputIterator>
+ // void assign (InputIterator first, InputIterator last);
+ // void assign (size_type n, const value_type& val);
+ void push_front (const value_type& val);
+ void pop_front();
+ void push_back (const value_type& val);
+ void pop_back();
+ // iterator insert (iterator position, const value_type& val);
+ // void insert (iterator position, size_type n, const value_type& val);
+ // template <class InputIterator>
+ // void insert (iterator position, InputIterator first, InputIterator last);
+ // iterator erase (iterator position);
+ // iterator erase (iterator first, iterator last);
+ // void swap (list& x);
+ // void resize (size_type n, value_type val = value_type());
+ // void clear();
+
+ // operations
+ // void splice (iterator position, list& x);
+ // void splice (iterator position, list& x, iterator i);
+ // void splice (iterator position, list& x, iterator first, iterator last);
+ // void remove (const value_type& val);
+ // template <class Predicate>
+ // void remove_if (Predicate pred);
+ // void unique();
+ // template <class BinaryPredicate>
+ // void unique (BinaryPredicate binary_pred);
+ //
+ // void merge (list& x);
+ // template <class Compare>
+ // void merge (list& x, Compare comp);
+ // void sort();
+ // template <class Compare>
+ // void sort (Compare comp);
+ // void reverse();
+
+ // observers
+ // allocator_type get_allocator() const;
+
+ private:
+ class PrivateList
+ {
+ public:
+ PrivateList(const value_type& val);
+ ~PrivateList();
+
+ PrivateList *next;
+ T val;
+ }
+ PrivateList *front;
+ PrivateList *back;
+ size_type size;
+ };
+}
+
+#endif
diff --git a/README.md b/README.md
index 915b177..ef3104c 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
# ft_containers
-ft_containers project of school 42.
+ft\_containers project of school 42.
diff --git a/stack.hpp b/Stack.htpp
index 64bfc66..64bfc66 100644
--- a/stack.hpp
+++ b/Stack.htpp
diff --git a/vector.hpp b/Vector.hpp
index 0f21995..0f21995 100644
--- a/vector.hpp
+++ b/Vector.hpp
diff --git a/list.hpp b/list.hpp
deleted file mode 100644
index c8645b4..0000000
--- a/list.hpp
+++ /dev/null
@@ -1,78 +0,0 @@
-#ifndef LIST_HPP
-# define LIST_HPP
-
-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()
- {
-
- }
-
- private:
- typedef struct
- {
- t_inner_list *next;
- T content;
- } t_inner_list;
- t_inner_list *front;
- t_inner_list *back;
- size_type size;
- };
-}
-
-#endif