码迷,mamicode.com
首页 > 其他好文 > 详细

队列实现

时间:2017-09-23 10:35:42      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:temp   name   logs   names   space   head   col   int   ret   

#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;
    }
};

 

队列实现

标签:temp   name   logs   names   space   head   col   int   ret   

原文地址:http://www.cnblogs.com/xiaoyu-10201/p/7580138.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!