C++双向链表
Posted ms_senda
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++双向链表相关的知识,希望对你有一定的参考价值。
template<class T> class DLLNode public: DLLNode() next = prev = 0; DLLNode(const T& el, DLLNode* n = 0, DLLNode * p = 0) info = el; next = n; prev = p; T info; DLLNode* next, * prev; ;
template<class T> class DoublyLinkedList public: DoublyLinkedList() head = tail = 0; void Add(const T&); T DeleteLast(); bool isEmpty() return head == 0; private: DLLNode<T>* head, * tail; ; template<class T> void DoublyLinkedList<T>::Add(const T& el) if (tail != 0) tail = new DLLNode<T>(el, 0, tail); tail->prev->next = tail; else head = tail = new DLLNode<T>(el); template<class T> T DoublyLinkedList<T>::DeleteLast() T el = tail->info; if (head == tail) delete head; head = tail = 0; else tail = tail->prev; delete tail->next; tail->next = 0; return el;
以上是关于C++双向链表的主要内容,如果未能解决你的问题,请参考以下文章