#include <iostream> using namespace std; class ListHead{ public: ListHead *prev,*next; }; class List{ public: ListHead *head; List() { head = new ListHead(); head->prev = head; head->next = head; } ~List() { delete head; head = NULL; } void _listAdd(ListHead *toAdd,ListHead*prev,ListHead *next) { next->prev = toAdd; toAdd->next = next; toAdd->prev = prev; prev->next = toAdd; } void listAdd(ListHead *toAdd) { _listAdd(toAdd,head,head->next); } void listAddTail(ListHead *toAdd) { _listAdd(toAdd,head->prev,head); } void _listDelete(ListHead*prev,ListHead *next) { prev->next = next; next->prev = prev; } void listDelete(ListHead *entry) { _listDelete(entry->prev,entry->next); entry->prev = NULL; entry->next = NULL; } int listEmpty() { return head->next == head; } };
时间: 2024-11-10 21:30:10