• <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 閱讀(1638) 評論(0)  編輯 收藏 引用

            亚洲国产精品综合久久一线| 久久久久亚洲精品日久生情| 久久er国产精品免费观看2| a级成人毛片久久| 三级韩国一区久久二区综合| 国内精品久久久久久久久电影网| 国产99久久精品一区二区| 日韩欧美亚洲综合久久影院Ds| 久久久久久伊人高潮影院| 久久r热这里有精品视频| 麻豆久久久9性大片| 免费观看久久精彩视频| 99精品久久精品一区二区| 久久久久国产精品麻豆AR影院| 亚洲国产另类久久久精品黑人 | 欧美午夜A∨大片久久 | 久久人人爽人人人人片av| 久久综合中文字幕| 欧美va久久久噜噜噜久久| 久久久久婷婷| 国产精品伊人久久伊人电影| 久久久噜噜噜久久中文福利| 日韩精品无码久久一区二区三| 热re99久久精品国产99热| 久久久久亚洲AV片无码下载蜜桃| 久久这里有精品| 一级A毛片免费观看久久精品| 免费精品99久久国产综合精品| 久久这里只有精品18| 亚洲综合伊人久久综合| 99久久国产综合精品女同图片| 狠狠色丁香婷婷久久综合五月| 久久黄色视频| 日本加勒比久久精品| 国产91久久综合| 国产成人久久精品麻豆一区 | 伊人色综合久久天天人手人婷| 久久综合成人网| 欧美精品九九99久久在观看| 久久人妻少妇嫩草AV蜜桃| 国产激情久久久久久熟女老人|