Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1091095
  • 博文数量: 252
  • 博客积分: 4561
  • 博客等级: 上校
  • 技术积分: 2833
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-15 08:23
文章分类

全部博文(252)

文章存档

2015年(2)

2014年(1)

2013年(1)

2012年(16)

2011年(42)

2010年(67)

2009年(87)

2008年(36)

分类: C/C++

2010-04-04 17:30:10

#include <iostream>

#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <time.h>

using namespace std;

class SinoSession {
        public:
                SinoSession();
                ~SinoSession();

                SinoSession *prev;
                SinoSession *next;

                int get_value() { return this->value; }

        private:
                int value;
};

SinoSession::SinoSession()
{
        prev = next = NULL;
        value = 1024;
}

SinoSession::~SinoSession()
{
}

class SinoSessionHead {
        public:
                SinoSessionHead();
                ~SinoSessionHead();

                int session_queue_tail(SinoSession *session);
                void __session_queue_before(SinoSessionHead *h, SinoSession *next, SinoSession *news);
                void __session_insert(SinoSession *news, SinoSession *prev,
                                        SinoSession *next, SinoSessionHead *h);
                SinoSession * session_dequeue(SinoSessionHead *h);
                SinoSession * session_peek(SinoSessionHead *h);
                void __session_unlink(SinoSession *s, SinoSessionHead *h);

                SinoSession *prev;
                SinoSession *next;
};

SinoSessionHead::SinoSessionHead()
{
        prev = (SinoSession *)this;
        next = (SinoSession *)this;
}

SinoSessionHead::~SinoSessionHead()
{
}

int SinoSessionHead::session_queue_tail(SinoSession *session)
{
        __session_queue_before(this, (SinoSession *)this, session);
}

void SinoSessionHead::__session_queue_before(SinoSessionHead *h, SinoSession *next, SinoSession *news)
{
        __session_insert(news, next->prev, next, h);
}

void SinoSessionHead::__session_insert(SinoSession *news,
                                SinoSession *prev, SinoSession *next,
                                SinoSessionHead *h)
{
        news->next = next;
        news->prev = prev;
        next->prev = prev->next = news;
}

SinoSession * SinoSessionHead::session_dequeue(SinoSessionHead *h)
{
        SinoSession *s = session_peek(h);
        if (s)
                __session_unlink(s, h);

        return s;
}

SinoSession * SinoSessionHead::session_peek(SinoSessionHead *list_)
{
        SinoSession *list = ((SinoSession *)list_)->next;
        if (list == (SinoSession *)list_)
                list = NULL;
        return list;

}

void SinoSessionHead::__session_unlink(SinoSession *skb, SinoSessionHead *list)
{
        SinoSession *next, *prev;

        next = skb->next;
        prev = skb->prev;
        skb->next = skb->prev = NULL;
        next->prev = prev;
        prev->next = next;

}

int main()
{
        SinoSessionHead head;

        SinoSession *session = new SinoSession;

        head.session_queue_tail(session);

        SinoSession *s = head.session_dequeue(&head);

        cout << s->get_value() << endl;
        delete s;

        return 0;
}


阅读(638) | 评论(1) | 转发(0) |
0

上一篇:clucene example 1

下一篇:split file

给主人留下些什么吧!~~

chinaunix网友2010-04-07 11:10:22

#include #include #include #include #include #include using namespace std; class SinoSessionHead { public: class SinoSession { public: SinoSession(); ~SinoSession(); SinoSession *prev; SinoSession *next; int get_value() { return this->value; } private: int value; }; SinoSessionHead(); ~SinoSessionHead(); int ses