/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* List.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/01 09:31:07 by cacharle #+# #+# */ /* Updated: 2020/02/01 09:38:20 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef LIST_HPP # define LIST_HPP namespace ft { template < typename T, typename Alloc = allocator > class List { typedef T value_type; typedef Alloc allocator_type; typedef allocator_type::reference reference; typedef allocator_type::const_reference const_reference; typedef allocator_type::pointer pointer; typedef allocator_type::const_pointer const_pointer; public: List(const allocator_type& alloc = allocator_type()); { front = nullptr; back = nullptr; size = 0; } // List(size_type n, const value_type& val = value_type(), const allocator_type& alloc = allocator_type()); // template // List(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type()); // List(const list& x); ~List() { while (size > 0) pop_front(); } // 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 { return front == nullptr; } size_type size() const { return size; } size_type max_size() const; // element access reference front() { return *front; } reference back() { return *back; } const_reference front() const; const_reference back(); // modifiers // template // void assign (InputIterator first, InputIterator last); // void assign (size_type n, const value_type& val); void push_front (const value_type& val) { PrivateList *nfront = new PrivateList(val); nfront->next = front; front = nfront; if (back == nullptr) back = front; size++; } void pop_front() { t_llist *nfront = front->next; if (size == 1) back = nullptr; delete front; front = nfront; size--; } 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++; } void pop_back() { t_llist *tmp = front; while (tmp->next != back) tmp = tmp->next; delete back; back = tmp; } // iterator insert (iterator position, const value_type& val); // void insert (iterator position, size_type n, const value_type& val); // template // 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 // void remove_if (Predicate pred); // void unique(); // template // void unique (BinaryPredicate binary_pred); // // void merge (list& x); // template // void merge (list& x, Compare comp); // void sort(); // template // void sort (Compare comp); // void reverse(); // observers // allocator_type get_allocator() const; private: class PrivateList { public: PrivateList(const value_type& val) { next = nullptr; val = val; } ~PrivateList() { delete val; } PrivateList *next; T val; } PrivateList *front; PrivateList *back; size_type size; }; } #endif