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

            久久久久免费精品国产| 久久伊人五月丁香狠狠色| 久久成人精品视频| 亚洲一区二区三区日本久久九| 很黄很污的网站久久mimi色| 女同久久| 69国产成人综合久久精品| 精品久久久久久国产免费了| 亚洲国产成人久久笫一页| 久久久精品2019免费观看| 久久一区二区三区99| 91久久婷婷国产综合精品青草| 久久国产V一级毛多内射| 久久久久久久久无码精品亚洲日韩| 国产亚洲精午夜久久久久久| 久久午夜无码鲁丝片秋霞| 久久国产热这里只有精品| 久久99亚洲网美利坚合众国| 久久久www免费人成精品| 久久国产综合精品五月天| 久久亚洲AV成人无码电影| 伊人色综合久久天天人守人婷 | 精品久久一区二区三区| 久久精品成人免费国产片小草| 成人免费网站久久久| 久久亚洲美女精品国产精品| 久久久久久精品免费看SSS | 久久精品国产亚洲精品| 秋霞久久国产精品电影院| 久久精品黄AA片一区二区三区| 久久久久久久波多野结衣高潮| 久久这里有精品视频| 天天做夜夜做久久做狠狠| 国产精品成人精品久久久| 91精品国产91久久久久久| 爱做久久久久久| 久久影视国产亚洲| 久久久久久久久久久| 久久精品无码午夜福利理论片| 久久精品人人做人人爽电影蜜月 | 色婷婷狠狠久久综合五月|