📄 my_list.h
字号:
template<class T>class CList{ struct node { T data; node* next; node(T _data, node* _next = NULL) : data(_data), next(_next) {} node() : next(NULL) {}; }; node* front; node* back; public: CList() : front(NULL), back(NULL) {} ~CList() { if (front != NULL) { while (front != NULL) { node *p = front; front = p->next; delete p; } } } void push_front(const T& t) { node* n = new node(t,front); if (front == NULL) { front = back = n; } else front = n; } void push_back(const T& t) { node* n = new node(t); if (front == NULL) { front = back = n; } else { back->next = n; back = n; } } class iterator { node* current; public: iterator(node* _c) : current(_c) {} iterator& operator++() { current = current->next; return *this; } iterator& operator++(int) { current = current->next; return *this; } T operator*() { return current->data; } T* operator->() { return &(current->data); } bool operator!=(iterator t) { return (current != t.current); } }; iterator begin() { return iterator(front); } iterator end() { return iterator(NULL); }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -