• <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>
            隨筆 - 8  文章 - 26  trackbacks - 0
            <2009年9月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            常用鏈接

            留言簿(5)

            隨筆檔案

            文章分類

            文章檔案

            相冊

            C++語言

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            #ifndef LIST_H
            #define LIST_H
            template
            <typename elemtype>class list_item 
            {
            public:
             list_item( elemtype, list_item
            <elemtype>* );
             list_item( 
            const list_item<elemtype>& );

             
            const elemtype date () const;
             
            const list_item<elemtype>* next() const
             
            void get_date ( const elemtype );
             
            void get_next ( const list_item<elemtype>* );

             
            void operator =const list_item<elemtype>& );
            private:
             elemtype  _date;
             list_item
            <elemtype> *_next; 
            }
            ;//單鏈表數據項類

            //數據項類代碼實現
            template<typename elemtype>
             list_item
            <elemtype>::list_item( elemtype ia = 0,
                   list_item
            <elemtype> *= 0 ) 
             
            {
               get_date( ia );
               
            if( p == NULL )
                get_next( NULL );
               
            else 
               
            {
                get_next( p
            ->next() );
                p
            ->get_next( this );
               }

              }

            template
            <typename elemtype>
             
            const elemtype 
             list_item
            <elemtype>::date() const 
             
            {
              
            return _date;
             }

            template
            <typename elemtype> const 
             list_item
            <elemtype>* list_item<elemtype>::
             next() 
            const  
             

              
            return _next;
             }

            template
            <typename elemtype>
             
            void list_item<elemtype>::get_date( const elemtype de )
             
            {
              _date 
            = de; 
             }

            template
            <typename elemtype>
             
            void list_item<elemtype>::
             get_next( 
            const list_item<elemtype> *pev )
             

              _next 
            = ( list_item<elemtype>* )pev; 
             }


            template
            <typename elemtype> class list
            {
            public:
             list();
             list( 
            const list<elemtype>& );
             
            ~list();

             
            const int size() const;
             
            const bool empty() const;
             
            void insert( const elemtype, const elemtype );
             
            void insert_front( const elemtype );
             
            void insert_end( const elemtype );
             
            void remove( const elemtype );
             
            void remove_all();
             
            void remove_front();
             
            void print() const;
             
            const list_item<elemtype>* find( const elemtype );

             
            void operator =const list<elemtype>& );

            private:
             
            //
             void down_size();
             
            void add_size();

             
            //
             list_item<elemtype> *at_front;
             list_item
            <elemtype> *at_end;
             list_item
            <elemtype> *at_move;
             
            int               _size;
            }
            ;//鏈表類定義

            //函數實現代碼
            //私有函數集合
            template<typename elemtype> 
             
            void list<elemtype>::add_size() 
             
            {
              
            ++_size; 
             }

            template
            <typename elemtype>
             
            void list<elemtype>::down_size() 
             
            {
              
            --_size; 
             }


            //公有函數集合
            template<typename elemtype>
             list
            <elemtype>::list() 
              at_front 
            = NULL;
              at_end 
            = NULL;
              _size 
            = 0;
             }

            template
            <typename elemtype>
             list
            <elemtype>::~list() 
             
            {
              remove_all();
             }

            template
            <typename elemtype>
             
            const bool list<elemtype>::empty() const
             
            {
              
            return size() == 0 ? false : true;
             }

            template
            <typename elemtype>
             
            const int list<elemtype>::size() const
             

              
            return _size;
             }

            template
            <typename elemtype>
             
            void list<elemtype>::insert_front( const elemtype iva )
             
            {
              list_item
            <elemtype> *pv = 
                
            new list_item<elemtype>( iva, 0 );
              
            if!at_front )
              
            {
               at_front 
            = at_end = pv;
              }

              
            else 
              
            {
               pv
            ->get_next( at_front );
               at_front 
            = pv;
              }

              add_size();
             }

            template
            <typename elemtype>
             
            void list<elemtype>::insert_end( const elemtype iva ) 
             
            {
              
            if( at_end == NULL) 
              
            {
               at_end 
            = at_front =
                 
            new list_item<elemtype>( iva, 0 );
              }

              
            else 
               at_end 
            = new list_item<elemtype>( iva, at_end ); 
              add_size();
             }

            template
            <typename elemtype> void list<elemtype>::
             insert( 
            const elemtype ixa, const elemtype iva ) 
             
            {
              list_item
            <elemtype> *pev = 
                ( list_item
            <elemtype>* )find( iva );
              
            if( pev == NULL )
              
            {
               cerr 
            << "err!" <<endl;
               
            return;
              }

              
            if( pev == at_front ) 
               insert_front( ixa );
              
            else {
               
            new list_item<elemtype>( ixa, pev );
               add_size();
              }

             }

            template
            <typename elemtype> const 
            list_item
            <elemtype>* list<elemtype>::
             find( 
            const elemtype iva )
             
            {
              list_item
            <elemtype> *at_move = at_front;
              
            while( at_move != NULL ) 
              
            {
               
            if( at_move->date() == iva )
                
            return at_move;
               at_move 
            = ( list_item<elemtype>* )at_move->next();
              }

               
            return NULL;
             }

            template
            <typename elemtype>
             
            void list<elemtype>::remove_front()
             
            {
              
            if( at_front )
              
            {
               list_item
            <elemtype> *pev = at_front;
               at_front 
            = ( list_item<elemtype>* )at_front->next();
               delete pev;
               down_size();
              }

             }

            template
            <typename elemtype>
             
            void list<elemtype>::remove( elemtype iva )
             
            {
              list_item
            <elemtype> *pev = at_front;
              
            while( pev && pev->date() == iva )
              
            {
               pev 
            = ( list_item<elemtype>* )pev->next();
               remove_front();
              }

              
            if!pev )
               
            return ;
              list_item
            <elemtype> *prv = pev;
              pev 
            = ( list_item<elemtype>* )pev->next();
              
            while( pev ) 
              
            {
               
            if( pev->date() == iva ) 
               
            {
                prv
            ->get_next( pev->next() );   
                down_size();
                delete pev;
                pev 
            = ( list_item<elemtype>* )prv->next();
                
            if( pev != NULL )
                
            {
                 at_end 
            = prv;
                 
            return;
                }

               }

               
            else 
               
            {
                prv 
            = pev;
                pev 
            = ( list_item<elemtype>* )pev->next();
               }

              }

             }

            template
            <typename elemtype>
             
            void list<elemtype>::remove_all()
             
            {
              
            while( at_front )
               remove_front();
              _size 
            = 0;
              at_front 
            = at_end = NULL;
             }

            template
            <typename elemtype>
             
            void list<elemtype>::print() const 
             
            {
              list_item
            <elemtype> *pev = at_front;
              cout 
            << '[' << size() << ']';
              cout 
            << '{';
              
            forint ix = 0; pev && ix < size(); ++ix ) 
              
            {
               cout 
            << pev->date() << ' ';
               pev 
            = ( list_item<elemtype>* )pev->next();
              }

              cout 
            << '}' << endl;
             }

            #endif
            轉載自:http://www.shnenglu.com/mzty/archive/2005/10/28/870.html
            posted on 2008-06-18 22:05 楊彬彬 閱讀(356) 評論(0)  編輯 收藏 引用 所屬分類: 數據結構
            亚洲欧洲中文日韩久久AV乱码| 麻豆AV一区二区三区久久| 国产精品久久久久9999高清| 国产精品久久久久久久| 9久久9久久精品| 久久久国产精品| 国产人久久人人人人爽| 国产真实乱对白精彩久久| 久久成人小视频| 91精品国产综合久久四虎久久无码一级 | 亚洲а∨天堂久久精品9966| 精品久久久久久久国产潘金莲| 少妇人妻88久久中文字幕| 久久久久国产视频电影| 热re99久久精品国99热| 热RE99久久精品国产66热| 狠狠狠色丁香婷婷综合久久俺| 亚洲国产精品无码久久九九| 久久99精品国产麻豆宅宅 | 日韩精品无码久久久久久| 激情综合色综合久久综合| a级成人毛片久久| 久久AV高潮AV无码AV| 久久久精品国产亚洲成人满18免费网站| 久久精品国产亚洲AV无码偷窥| 久久久青草青青国产亚洲免观| 国产精品久久久久久久久| 欧洲精品久久久av无码电影| 一级做a爰片久久毛片毛片| 久久久99精品成人片中文字幕 | 久久综合给合久久狠狠狠97色| 亚洲一区精品伊人久久伊人| 狠狠人妻久久久久久综合| 久久青草国产精品一区| 久久精品成人免费网站| 成人免费网站久久久| 国产99久久精品一区二区| 99精品久久精品一区二区| 99国产精品久久久久久久成人热| 国内精品人妻无码久久久影院| 久久亚洲精品成人av无码网站|