• <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)  編輯 收藏 引用

            亚洲?V乱码久久精品蜜桃| 精品久久久久中文字幕一区| 狠狠色丁香婷婷久久综合| 亚洲va久久久久| 精品国产VA久久久久久久冰| 久久国产乱子精品免费女| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | a级成人毛片久久| 久久久久久国产精品无码下载| 久久国产精品无| 国产精品gz久久久| 亚洲AV无码成人网站久久精品大| 久久久久久久综合日本亚洲| 青青草原综合久久大伊人| 天天爽天天爽天天片a久久网| 久久精品国产AV一区二区三区 | 欧美伊人久久大香线蕉综合69 | 久久久久人妻一区二区三区vr| 日韩亚洲欧美久久久www综合网| 99久久国产宗和精品1上映| 国产精品欧美久久久久无广告| 人妻少妇久久中文字幕一区二区| 99久久国产综合精品网成人影院| 欧美一区二区久久精品| 久久久久无码国产精品不卡| 久久免费精品视频| 精品乱码久久久久久久| 无码超乳爆乳中文字幕久久| 亚洲人成电影网站久久| 久久久久亚洲AV综合波多野结衣 | 亚洲日本va中文字幕久久| 伊人久久一区二区三区无码| 精品久久久无码中文字幕| 91秦先生久久久久久久| 欧美一区二区精品久久| 欧美激情精品久久久久| 91精品观看91久久久久久| 国产激情久久久久影院老熟女| 国产成人综合久久久久久| 久久精品国产半推半就| AAA级久久久精品无码区|