1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/sniperHW-clientnet-select

Клонировать/Скачать
dlist.h 969
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
sniperHW Отправлено 12.06.2015 13:18 a9db8f2
#ifndef _DLIST_H
#define _DLIST_H
class dlist;
struct dnode{
dnode():next(NULL),pre(NULL),_dlist(NULL){}
dnode *next;
dnode *pre;
dlist *_dlist;
};
class dlist{
public:
dlist():size(0){
head.next = &tail;
tail.pre = &head;
}
size_t Size(){
return size;
}
bool Empty(){
return size == 0;
}
dnode *Begin(){
if(Empty())return &tail;
return head.next;
}
dnode *End(){
return &tail;
}
void Push(dnode *n){
if(n->_dlist || n->next || n->pre) return;
tail.pre->next = n;
n->pre = tail.pre;
tail.pre = n;
n->_dlist = this;
n->next = &tail;
++size;
}
void Remove(dnode *n)
{
if(n->_dlist != this || (!n->pre && !n->next))
return;
n->pre->next = n->next;
n->next->pre = n->pre;
n->pre = n->next = NULL;
n->_dlist = NULL;
--size;
}
dnode* Pop(){
if(Empty())
return NULL;
else
{
dnode *n = head.next;
Remove(n);
return n;
}
}
private:
dnode head;
dnode tail;
size_t size;
};
#endif

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/sniperHW-clientnet-select.git
git@api.gitlife.ru:oschina-mirror/sniperHW-clientnet-select.git
oschina-mirror
sniperHW-clientnet-select
sniperHW-clientnet-select
master