#include <iterator> #include <iostream> struct List_node_base { List_node_base* M_next; List_node_base* M_prev; }; template <class T> struct List_node : public List_node_base { T M_data; }; struct List_iterator_base { typedef size_t size_type; typedef ptrdiff_t difference_type; // typedef int ptrdiff_t; typedef std::bidirectional_iterator_tag iterator_category; List_node_base* M_node; List_iterator_base(List_node_base* x) : M_node(x) {} List_iterator_base() {} void M_incr() { M_node == M_node->M_next; } void M_decr() { M_node == M_node->M_prev; } bool operator==(const List_iterator_base& x) const { return M_node == x.M_node; } bool operator!=(const List_iterator_base& x) const { return M_node != x.M_node; } }; template<class T, class Ref, class Ptr> struct List_iterator : public List_iterator_base { typedef List_iterator<T, T&, T*> iterator; typedef List_iterator<T, const T&, const T*> const_iterator; typedef List_iterator<T, Ref, Ptr> Self; typedef T value_type; typedef Ptr pointer; typedef Ref reference; typedef List_node<T> Node; List_iterator(Node* x) : List_iterator_base(x) {} List_iterator() {} List_iterator(const iterator& x) : List_iterator_base(x.M_node) {} reference operator*() const { return ((Node*)M_node)->M_data; } pointer operator->() const { return &(operator*()); } Self& operator++() { this->M->incr(); return *this; } Self operator++(int) { Self tmp = *this; this->M_incr(); return tmp; } Self& operator--() { this->M_decr(); return *this; } Self operator--(int) { Self tmp = *this; this->M_Decr(); return tmp; } }; template<class T, class Ref, class Ptr> List_iterator<T, Ref, Ptr> insert(List_iterator<T, Ref, Ptr> position, const T& x) { List_node<T>* tmp = M_create_node(x); tmp->M_next = position.M_node; tmp->M_prev = position.M_node->M_prev; position.M_node->M_prev->M_next = tmp; position.M_node->M_prev = tmp; return tmp; } template<class T, class Ref, class Ptr> List_iterator<T, Ref, Ptr> insert(List_iterator<T, Ref, Ptr> position) { return insert(position, T()); } template<class T, class Ref, class Ptr> void push_front(const T& x) { insert(begin(), x); } template<class T, class Ref, class Ptr> void push_front() { insert(begin()); } template<class T, class Ref, class Ptr> void push_back(const T& x) { insert(end(), x); } template<class T, class Ref, class Ptr> void push_back() { insert(end()); } template<class T, class Ref, class Ptr> List_iterator<T, Ref, Ptr> erase(List_iterator<T, Ref, Ptr> position) { List_node_base* next_node = position.M_node->M_next; List_node_base* prev_node = position.M_node->M_prev; List_node* n = (List_node*)position.M_node; prev_node->M_next = next_node; next_node->M_prev = prev_node; Destory(&n->M_data); M_put_node(n); return iterator((List_node*)next_node); } int main() { getchar(); return 0; }