• <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

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

            動態(tài)循環(huán)隊列模板類——鏈表實現(xiàn)

             

            //template_by_abilitytao_ACM
            //Begin_template_myqueue
            //這是一個非常高效的循環(huán)鏈表隊列
            #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有可能嗎?如果內(nèi)存不夠系統(tǒng)內(nèi)部有 返回值嗎,猜:返回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()//為了提高本模板的兼容性,故提供此函數(shù),其實函數(shù)的返回值永遠不可能為1;
            {
                
            return false;
            }

            //endtemplate_by_abilitytao_ACM

            ////////////////////////////////////////////////////////////////////下面是測試數(shù)據(jù)////////////////////////////////////////////////////////////////////////////
            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 閱讀(1637) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久久久国产| 99久久精品国产一区二区蜜芽| 无码人妻久久一区二区三区蜜桃| 亚洲欧美精品一区久久中文字幕| 无码乱码观看精品久久| 香蕉久久夜色精品升级完成| 久久精品www人人爽人人| 久久精品国产色蜜蜜麻豆| 日韩AV毛片精品久久久| 国产精品久久久亚洲| 女人香蕉久久**毛片精品| 久久久久国产精品人妻| 久久久免费精品re6| 亚洲一区精品伊人久久伊人| 99久久久国产精品免费无卡顿| 91久久精品国产91性色也| 亚洲国产精品成人久久| 色综合久久88色综合天天 | 久久er99热精品一区二区| 91久久精品电影| 狠狠色丁香婷婷久久综合不卡| 国内精品欧美久久精品| 久久精品国产精品亚洲精品 | 久久精品国产WWW456C0M| 思思久久99热免费精品6| 精品久久久无码人妻中文字幕豆芽| 国产视频久久| 久久综合综合久久97色| 97久久精品无码一区二区| 久久久久亚洲AV无码观看| 免费精品久久久久久中文字幕| 久久国产热这里只有精品| 久久精品国产免费一区| 996久久国产精品线观看| 久久精品中文无码资源站| 欧美激情一区二区久久久| 精品熟女少妇aⅴ免费久久| 色综合合久久天天综合绕视看| 国产精品久久久久久影院| 久久婷婷色香五月综合激情| 亚洲精品乱码久久久久久不卡|