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

            S.l.e!ep.¢%

            像打了激速一樣,以四倍的速度運(yùn)轉(zhuǎn),開(kāi)心的工作
            簡(jiǎn)單、開(kāi)放、平等的公司文化;尊重個(gè)性、自由與個(gè)人價(jià)值;
            posts - 1098, comments - 335, trackbacks - 0, articles - 1
              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            寫(xiě)了個(gè)雙向鏈表

            Posted on 2009-04-05 23:43 S.l.e!ep.¢% 閱讀(1947) 評(píng)論(3)  編輯 收藏 引用 所屬分類: Data Struct

            #include<iostream.h>

            template<class Type>
            struct nodeType
            {??
            ?Type info;
            ?nodeType<Type>? *link;
            ?nodeType<Type>? *back;
            };

            template<class Type>
            class doublelist
            {
            public:
            ?doublelist();
            ?// doublelist(const doublelist<Type>& otherlist);
            ?const doublelist<Type>&operator=(const doublelist<Type>&otherlist);

            ?virtual ~doublelist();

            ?void initializelist();
            ??? void destory();

            ?bool isEmptylist();
            ?void print();
            ?void rprint();
            ?int? length();

            ??? void insertItem(const Type& insertItem);
            ?void deleteItem(const Type& deleteItem);

            private:
            ??? nodeType<Type>? *first;
            };

            template<class Type>
            const doublelist<Type>& doublelist<Type>::operator=(const doublelist<Type>& otherlist)
            {??
            ??? if(first != NULL)
            ?{?
            ??destory();
            ?}

            ?if(this != &otherlist)
            ?{?
            ??if(otherlist.first == NULL)
            ??{
            ???first = NULL;
            ??}
            ??else
            ??{??
            ???nodeType<Type>* pointer = otherlist.first;
            ???nodeType<Type>* this_pointer = first;
            ???
            ??????????? while( pointer != NULL )
            ???{
            ????nodeType<Type>* newNode = new nodeType<Type>;
            ????newNode->info = pointer->info;
            ????newNode->link = NULL;
            ????newNode->back = NULL;

            ????if( this_pointer == NULL )
            ????{
            ?????this_pointer = first = newNode;
            ?????newNode->back = NULL;
            ?????newNode->link = NULL;
            ????}
            ????else
            ????{
            ?????newNode->back = this_pointer;
            ?????newNode->link = NULL;

            ?????this_pointer->link = newNode;
            ?????this_pointer = this_pointer->link;
            ????}????????
            ????
            ????pointer = pointer->link;
            ???}???
            ??}
            ?}

            ?return *this;
            }

            template<class Type>
            doublelist<Type>::~doublelist()
            {
            ?nodeType<Type>? *temp;
            ???
            ?while( first != NULL)
            ?{??
            ??temp? = first;
            ??first = first->link;
            ??delete temp;
            ?}
            ?
            ?//cout<<"析構(gòu)函數(shù)被調(diào)用"<<endl;
            }

            template<class Type>
            doublelist<Type>::doublelist()
            {????
            ?first = NULL;
            }

            template<class Type>
            void doublelist<Type>::initializelist()
            {?
            ?doublelist<Type>::destory();
            }

            template<class Type>
            bool doublelist<Type>::isEmptylist()
            {?
            ?return(first == NULL);
            }

            template<class Type>
            void? doublelist<Type>::destory()
            {
            ?nodeType<Type> *temp;
            ?
            ?while( first != NULL)
            ?{
            ??temp? = first;
            ??first = first->link;
            ??delete temp;
            ?}
            }

            template<class Type>
            void doublelist<Type>::print()
            {?
            ?nodeType<Type> *current;
            ?current=first;
            ?while(current!=NULL)
            ?{
            ??cout<<current->info<<" ";
            ??????? current=current->link;
            ?}
            }

            template<class Type>
            void doublelist<Type>::rprint()
            {?
            ?nodeType<Type> *current = first;
            ?while(current!=NULL && current->link!= NULL)
            ??current = current->link;

            ?while(current!=NULL)
            ?{
            ??cout<<current->info<<" ";
            ??????? current=current->back;
            ?}
            }

            template<class Type>
            int doublelist<Type>::length()
            {??
            ?int count=0;
            ?nodeType<Type> *current;
            ?current=first;
            ?while(current!=NULL)
            ?{
            ??count++;
            ??current=current->link;
            ?}
            ?return count;
            }

            template<class Type>
            void doublelist<Type>::insertItem(const Type& insertItem)
            {
            ?nodeType<Type>* pointer = first;
            ?bool bFind = false;

            ?while( pointer != NULL )
            ?{
            ??if( pointer->info == insertItem )
            ??{
            ???bFind = true;
            ???break;
            ??}
            ??else
            ??{
            ???pointer = pointer->link;
            ??}
            ?}

            ?if( bFind )
            ?{
            ??cout << insertItem << " have already exist!!" << endl;
            ?}
            ?else
            ?{
            ??nodeType<Type>* newnode = new nodeType<Type>();

            ??if( first == NULL )
            ??{
            ???first = newnode;
            ????? newnode->back = NULL;
            ??}
            ??else
            ??{
            ???pointer = first;
            ???while( pointer->link != NULL )
            ????pointer = pointer->link;

            ???pointer->link = newnode;
            ???newnode->back = pointer;
            ??}

            ??newnode->link = NULL;
            ??newnode->info = insertItem;
            ?}
            }

            void main()
            {
            ?doublelist<int> b,c;
            ?
            ?int num = 0, i = 0, j = 0;
            ?cout<<"please input the count of number:"<<endl;
            ?cin>>num;

            ?while(i < num)
            ?{
            ??cout<<"please input the number:";
            ??cin >> j;
            ??cout<<endl;
            ??b.insertItem(j);
            ??i++;
            ?}

            ?cout << "b normal: ";
            ??? b.print();
            ?cout << endl;

            ?c=b;
            ?
            ?cout << "normal: ";
            ?c.print();
            ?cout << endl;
            ?
            ?cout << "not normal: ";
            ?c.rprint();
            ?cout << endl;
            }

            Feedback

            # re: 寫(xiě)了個(gè)雙向鏈表  回復(fù)  更多評(píng)論   

            2009-04-06 00:16 by 陳梓瀚(vczh)
            你的接口表達(dá)出來(lái)的不是一個(gè)鏈表,而是一個(gè)集合。而且好像還沒(méi)辦法從doublelist<T>里面訪問(wèn)那些內(nèi)容……

            # re: 寫(xiě)了個(gè)雙向鏈表  回復(fù)  更多評(píng)論   

            2009-04-06 09:16 by S.l.e!ep.¢%
            不好意思,樓上的,被你看穿了,我會(huì)改進(jìn)的。

            # re: 寫(xiě)了個(gè)雙向鏈表  回復(fù)  更多評(píng)論   

            2009-04-06 23:59 by wZt
            雙向鏈表似乎沒(méi)有很復(fù)雜 即使你想寫(xiě)雙向列表也不用這么多代碼。。

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


            日韩欧美亚洲综合久久影院Ds| 色偷偷久久一区二区三区| 久久99精品久久久久久齐齐| 国产99久久九九精品无码| 久久精品三级视频| 久久精品国产精品亚洲精品| 九九精品99久久久香蕉| 久久成人国产精品一区二区| 一本一道久久a久久精品综合| av色综合久久天堂av色综合在| 久久人人爽人人爽人人片AV不| 精品一久久香蕉国产线看播放| 婷婷久久香蕉五月综合加勒比| 品成人欧美大片久久国产欧美... 品成人欧美大片久久国产欧美 | 大伊人青草狠狠久久| 亚洲&#228;v永久无码精品天堂久久| 久久久无码精品亚洲日韩京东传媒| 久久99国产精品久久99| 精品综合久久久久久97| 久久人人爽人人爽人人片AV麻豆 | 国产精品激情综合久久| 久久久久久夜精品精品免费啦 | 久久婷婷五月综合色奶水99啪| 国产精品久久久久乳精品爆| 成人妇女免费播放久久久| 久久亚洲日韩看片无码| 久久精品国产一区二区| 国产精品免费看久久久香蕉| 国产精品久久久久…| 久久久久女人精品毛片| 婷婷伊人久久大香线蕉AV| 亚洲综合伊人久久综合| 亚洲欧美一区二区三区久久| 九九热久久免费视频| 理论片午午伦夜理片久久 | 国产香蕉97碰碰久久人人| 99久久国产综合精品网成人影院| 久久99国产综合精品| 国产精品福利一区二区久久| 97久久超碰国产精品旧版| 国产精品久久久久影视不卡|