• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            The Fourth Dimension Space

            枯葉北風寒,忽然年以殘,念往昔,語默心酸。二十光陰無一物,韶光賤,寐難安; 不畏形影單,道途阻且慢,哪曲折,如渡飛湍。斬浪劈波酬壯志,同把酒,共言歡! -如夢令

            動態循環隊列模板類——鏈表實現

             

            //template_by_abilitytao_ACM
            //Begin_template_myqueue
            //這是一個非常高效的循環鏈表隊列
            #include<iostream>
            #include
            <cmath>
            #include
            <algorithm>
            #include
            <cstring>
            #include
            <cstdio>
            using namespace std;

            struct node {
                
            int data;
                node
            * next;
            }
            ;

            class myqueue
            {
            private:
                node 
            *prear;
                
            int lenth;
            public:
                myqueue();
                
            int push(int num);
                
            int pop();
                
            int front();
                
            int rear();
                
            int len();
                
            bool empty();
                
            bool full();
                
            }
            ;


            myqueue::myqueue()
            {

                prear
            =new node;
                prear
            ->data=0x7fffffff;
                prear
            ->next=prear;
                lenth
            =0;
            }



            int myqueue::push(int num)//入隊成功返回1,否則返回0 。問:(返回0有可能嗎?如果內存不夠系統內部有 返回值嗎,猜:返回null?)
            {
                
            {
                    node 
            *p=new node;
                    p
            ->data=num;
                    p
            ->next=prear->next;
                    prear
            ->next=p;
                    prear
            =p;
                    lenth
            ++;
                    
            return 1;
                }

                
            return 0;
            }


            int myqueue::pop()//如果出隊成功返回1,勾著否則返回0;
            {
                
            if(prear->next==prear)
                    
            return 0;
                node 
            *p=prear->next;
                node 
            *q=prear->next->next;
                p
            ->next=q->next;
                delete q;
                
            if(p=p->next)
                    prear
            =p;
                
            --lenth;
            }


            int myqueue::front()//隊列為空返回0,否則返回隊首元素的值
            {

                
            if(prear->next==prear)
                    
            return 0;
                node
            *p=prear->next->next;
                
            return p->data;

            }


            int myqueue::rear()//隊列為空返回值為0,否則返回隊尾元素的值
            {
                
            if(prear->next==prear)
                    
            return 0;
                
            return prear->data;
            }


            int myqueue::len()
            {
                
            return lenth;
            }


            bool myqueue::empty()
            {

                
            if(prear->next==prear)
                    
            return true;
                
            else
                    
            return false;
            }


            bool myqueue::full()//為了提高本模板的兼容性,故提供此函數,其實函數的返回值永遠不可能為1;
            {
                
            return false;
            }

            //endtemplate_by_abilitytao_ACM

            ////////////////////////////////////////////////////////////////////下面是測試數據////////////////////////////////////////////////////////////////////////////
            int main ()
            {

                myqueue test;
                
            int a=test.len();
                
            bool b=test.empty();
                test.push(
            1);
                test.push(
            2);
                a
            =test.front();
                a
            =test.rear();
                a
            =test.len();
                b
            =test.empty();
                b
            =test.full();
                a
            =test.pop();
                a
            =test.front();
                a
            =test.rear();
                a
            =test.pop();
                a
            =test.front();
                a
            =test.rear();

            }


            posted on 2009-03-02 21:00 abilitytao 閱讀(1632) 評論(0)  編輯 收藏 引用

            国产高清国内精品福利99久久| 久久久久国产精品人妻| 久久中文娱乐网| 久久久久无码精品国产app| 久久综合偷偷噜噜噜色| 亚洲国产精品无码久久| 国产成人无码精品久久久免费| 久久精品综合网| 亚洲国产精久久久久久久| 亚洲а∨天堂久久精品| 国产精品视频久久久| 一本久久免费视频| 久久久综合九色合综国产| 国产成人精品综合久久久| 国产综合成人久久大片91| 性做久久久久久久| 亚洲精品tv久久久久| 国产午夜精品久久久久免费视| 一级a性色生活片久久无少妇一级婬片免费放 | 亚洲国产成人久久综合一 | 久久精品国产亚洲5555| 麻豆一区二区99久久久久| 久久精品国产只有精品66| 精品国产91久久久久久久| 久久精品国产久精国产一老狼| 久久精品国产99久久丝袜| 久久国产精品成人免费 | 精品免费久久久久国产一区| 久久人人爽人人爽人人AV| 怡红院日本一道日本久久| 久久精品国产99久久久| 亚洲午夜久久久久久噜噜噜| 伊人热热久久原色播放www | 久久99精品国产麻豆宅宅| 久久无码人妻一区二区三区| 久久狠狠爱亚洲综合影院| 亚洲精品乱码久久久久久蜜桃| 九九热久久免费视频| 欧美粉嫩小泬久久久久久久| 久久综合九色欧美综合狠狠| 久久精品亚洲欧美日韩久久|