• <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.¢%

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

            寫了個雙向鏈表

            Posted on 2009-04-05 23:43 S.l.e!ep.¢% 閱讀(1932) 評論(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<<"析構函數被調用"<<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: 寫了個雙向鏈表  回復  更多評論   

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

            # re: 寫了個雙向鏈表  回復  更多評論   

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

            # re: 寫了個雙向鏈表  回復  更多評論   

            2009-04-06 23:59 by wZt
            雙向鏈表似乎沒有很復雜 即使你想寫雙向列表也不用這么多代碼。。
            国产成人无码精品久久久久免费| 亚洲午夜久久久久久久久久| 91亚洲国产成人久久精品网址| 久久久国产精品福利免费 | 日韩精品久久久久久免费| 国产午夜精品久久久久免费视| 亚洲狠狠久久综合一区77777| 青青热久久国产久精品| 无码人妻久久一区二区三区免费| 四虎国产精品免费久久5151| 久久国内免费视频| 国产午夜精品理论片久久| 中文字幕人妻色偷偷久久| 国产精品热久久无码av| 久久人人爽人人爽人人AV| 国产香蕉97碰碰久久人人| 久久综合亚洲欧美成人| 婷婷久久精品国产| 中文精品久久久久国产网址| 狼狼综合久久久久综合网| 久久久久亚洲av综合波多野结衣| 久久精品国产亚洲麻豆| 亚洲狠狠婷婷综合久久蜜芽| 久久综合视频网| 久久影院亚洲一区| 99久久精品九九亚洲精品| 69久久夜色精品国产69| 精品久久久无码21p发布| 久久夜色撩人精品国产| 国产成人久久精品二区三区| 久久99热国产这有精品| 欧美大香线蕉线伊人久久| 热re99久久精品国99热| 国内精品久久久久影院薰衣草| 思思久久99热只有频精品66| 久久亚洲中文字幕精品一区| 久久精品亚洲乱码伦伦中文| 国内精品久久久久久久久| 国产高潮久久免费观看| 狠狠色综合网站久久久久久久| 久久青草国产精品一区|