• <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>
            #ifndef LIST_HPP
            #define LIST_HPP

            #include 
            <iostream>
            #include 
            <string>

            using namespace std;

            #define DefaultListSize  1000

            template
            < typename Elem>
            class List
            {
                
            public:
                    
            virtual void clear() = 0;                           // 清空表
                    virtual bool insert( const Elem& )= 0;              // 從表中當前位置插入元素
                    virtual bool append( const Elem& )= 0;              // 從表中后面插入元素
                    virtual bool remove( Elem& )= 0;                    // 移除該元素,并且用引用返回該元素
                    virtual void setStart() = 0;                        // 將表當前位置指向第一個
                    virtual void setEnd() = 0;                          // 將表當前位置指向最后元素
                    virtual void pre() = 0;                            // 將指針移向當前位置前一個
                    virtual void next() = 0;                            // 將指針移向當前位置的下一個
                    virtual int  rightLength()          const= 0;       // 指針后面數據的大小
                    virtual int  leftLength()           const= 0;       // 指針前面數據的大小
                    virtual bool setPos( int pos )= 0;                  // 設置當前指針
                    virtual bool getValue( Elem& )      const= 0;       // 獲得當前指針所指元素
                    virtual void print()                const= 0;       // 輸出信息

                    
            virtual bool find( Elem const& data )= 0;           //  能否在表中找到元素 data
                    virtual int  length()               const= 0;       //  整個表的長度
                    virtual bool empty()                const= 0;       //  表是否為空
            };

            #endif



            #ifndef ALIST_HPP
            #define ALIST_HPP

            #include 
            "List.hpp"

            template
            <typename Elem>
            class AList: public List<Elem>
            {
            private:
                
            int   maxSize;
                
            int   listSize;
                
            int   fence;
                Elem
            * listArray;

            public:
                AList( 
            int size= DefaultListSize );
                
            ~AList();
                
                
            void clear();
                
            bool insert( const Elem& );
                
            bool append( const Elem& );
                
            bool remove( Elem& );
                
            void setStart() ;
                
            void setEnd() ;
                
            void prev() ;
                
            void next();
                
            int  rightLength()          const;
                
            int  leftLength()           const;
                
            bool setPos( int pos );
                
            bool getValue( Elem& )      const;
                
            void print()                const;

                
            int  length()               const
                
            bool find( Elem const& data );
                
            bool empty()                const;

                
            int  getMaxSize() const;
                
            int  getListSize() const;
                
            int  getFence() const;

                AList
            <Elem>& operator= ( AList<Elem>& t );
                Elem
            & operator[]( int i );
            };


            template
            <typename Type>
            AList
            <Type>::AList( int size )
            {
                maxSize
            = size;
                listSize
            = fence= 0;

                listArray
            = new Type[maxSize];
            }


            template
            <typename Type>
            AList
            <Type>::~AList()
            {
                delete [] listArray;
            }


            template
            <typename Type>
            void AList<Type>::clear()
            {
                listSize
            = fence= 0;
            }


            template
            <typename Type>
            bool AList<Type>::insert( Type const& Item )
            {
                
            if( listSize== maxSize ) return false;

                
            forint i= listSize; i> fence; i-- )
                    listArray[i]
            = listArray[i-1];

                listArray[fence]
            = Item;
                listSize
            ++;

                
            return true;
            }


            template
            <typename Type>
            bool AList<Type>::append( Type const& Item )
            {
                
            if( listSize== maxSize ) return false;

                listArray[listSize
            ++]= Item;
                
            return true;
            }


            template
            <typename Type>
            bool AList<Type>::remove( Type& Item )
            {
                
            if( rightLength()== 0 ) return false;

                
            forint i= fence; i< listSize- 1++i )
                    listArray[i]
            = listArray[i+1];

                listSize
            --;
                
            return true;
            }


            template
            <typename Type>
            void AList<Type>::prev()
            {
                
            if(  fence> 0 ) fence--;
            }


            template
            <typename Type>
            void AList<Type>::next()
            {
                
            if( fence<= listSize ) fence++;
            }


            template
            <typename Type>
            int AList<Type>::rightLength() const
            {
                
            return listSize- fence;
            }


            template
            <typename Type>
            int AList<Type>::leftLength() const
            {
                
            return fence;
            }

            template
            <typename Type>
            int AList<Type>::length() const
            {
                
            return listSize;
            }


            template
            <typename Type>
            bool AList<Type>::setPos( int pos ) 
            {
                
            if( pos< 0 || pos> listSize ) return false;

                fence
            = pos;
                
            return true;
            }

            template
            <typename Type>
            bool AList<Type>::getValue( Type& Item ) const
            {
                
            if( fence< 0 || fence>= listSize ) return false;

                Item
            = listArray[fence];
                
            return true;
            }

            template
            <typename Type>
            void AList<Type>::setStart()
            {
                fence
            = 0;
            }


            template
            <typename Type>
            void AList<Type>::setEnd()
            {
                fence
            = listSize;
            }


            template
            <typename Type>
            bool AList<Type>::find( Type const& data )
            {
                
            forint i= 0; i< listSize; ++i )
                
            if( listArray[i]== data ) return true;

                
            return false;
            }


            template
            <typename Type>
            void AList<Type>::print() const
            {
                
            int t= 0;
                
            for( t= 0; t< fence; ++t ) cout << listArray[t] << ' ';
                cout 
            << '|' << ' ';
                
            for( t= fence; t< listSize; ++t ) cout << listArray[t] << ' ';
            }


            template
            <typename Type>
            bool AList<Type>::empty() const
            {
                
            return listSize== 0;
            }

            template
            <typename Type>
            AList
            <Type>& AList<Type>::operator= ( AList<Type>& t )
            {
                maxSize
            = t.getMaxSize();
                listSize
            = t.getListSize();
                fence
            = t.getFence();

                listArray
            = new Type[maxSize];
                
            forint i= 0; i< listSize; ++i )
                listArray[i]
            = t[i];
                
                
            return *this;
            }


            template
            <typename Type>
            Type
            & AList<Type>::operator[]( int i )
            {
                
            return listArray[i];
            }


            template
            <typename Type>
            int AList<Type>::getMaxSize() const
            {
                
            return maxSize;
            }


            template
            <typename Type>
            int AList<Type>::getListSize() const
            {
                
            return listSize;
            }


            template
            <typename Type>
            int AList<Type>::getFence() const
            {
                
            return fence;
            }

            #endif





            #ifndef LLIST_HPP
            #define LLIST_HPP

            #include 
            "list.hpp"
            #include 
            <iostream>

            using namespace std;


            /////////////////////////////////////////////////////////
            //           結點類, 使用可利用空間表實現
            /////////////////////////////////////////////////////////


            //////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////


            template
            <typename Type>
            class CLink
            {
                
            private:
                    
            static CLink<Type>* freelist;

                
            public:
                    Type   element;
                    CLink
            * next;

                
            public:
                    
            void* operator new   ( size_t );
                    
            void  operator delete( void*  );

                    CLink();
                    CLink( Type, CLink
            <Type>* );
            };

            template
            <typename Type>
            CLink
            <Type>* CLink<Type>::freelist= NULL;

            template
            <typename Type>
            CLink
            <Type>::CLink()
            {}

            template
            <typename Type>
            CLink
            <Type>::CLink( Type a, CLink<Type>* b ):
            element(a), next(b)
            {}

            template
            <typename Type>
            void* CLink<Type>::operator new( size_t )
            {
                
            if( freelist== NULL ) return ::new CLink<Type>;

                CLink
            <Type>* temp= freelist;
                freelist
            = freelist->next;

                
            return temp;
            }

            template
            <typename Type>
            void CLink<Type>::operator delete( void* t )
            {
                ((CLink
            <Type>*)t)->next= freelist;

                freelist
            = ( CLink<Type>* )t;
            }


            /////////////////////////////////////////////////////////////////
            /////////////////////////////////////////////////////////////////



            /////////////////////////////////////////////////////////////////
            ///  鏈表實現
            /////////////////////////////////////////////////////////////////



            template
            <typename Type>
            class LList: public List<Type>
            {
                
            private:
                    CLink
            <Type>* head, *tail, *fence;
                    
            int  leftcnt, rightcnt;

                
            public:
                    LList( 
            int size= DefaultListSize );
                    
            ~LList();

                    
            void clear();
                    
            bool insert( const Type& );
                    
            bool append( const Type& );
                    
            bool remove( Type& );
                    
            void setStart() ;
                    
            void setEnd() ;
                    
            void pre() ;
                    
            void next();
                    
            int  rightLength()          const;
                    
            int  leftLength()           const;
                    
            bool setPos( int pos );
                    
            bool getValue( Type& )      const;
                    
            void print()                const;

                    
            int  length()               const
                    
            bool find( Type const& data );
                    
            bool empty()                const;

                    
            void init();
                    
            void removeall();

                    
            bool setvalue( int pos, Type t );
                    
            bool setvalue( Type t );
            };

            template
            <typename Type>
            LList
            <Type>::LList( int size )
            {
                init();
            }


            template
            <typename Type>
            void LList<Type>::init()
            {
                fence
            = tail= head= new CLink<Type>;
                leftcnt
            = rightcnt= 0;
            }

            template
            <typename Type>
            void LList<Type>::removeall()
            {
                
            while( head!= NULL )
                {
                    fence
            = head;
                    head
            = head->next;
                    delete fence;
                }
            }

            template
            <typename Type>
            LList
            <Type>::~LList()
            {
                removeall();
            }

            template
            <typename Type>
            void LList<Type>::clear()
            {
                removeall();
                init();
            }

            template
            <typename Type>
            void LList<Type>::setStart()
            {
                fence
            = head;
                rightcnt
            += leftcnt;
                leftcnt
            = 0;
            }

            template
            <typename Type>
            void LList<Type>::setEnd()
            {
                fence
            = tail;
                leftcnt
            += rightcnt;
                rightcnt
            = 0;
            }

            template
            <typename Type>
            void LList<Type>::next()
            {
                
            if( fence!= tail ) fence= fence->next, rightcnt--, leftcnt++;
            }

            template
            <typename Type>
            int LList<Type>::leftLength() const
            {
                
            return leftcnt;
            }

            template
            <typename Type>
            int LList<Type>::rightLength() const
            {
                
            return rightcnt;
            }

            template
            <typename Type>
            bool LList<Type>::getValue( Type& it ) const
            {
                
            if( rightcnt== 0 ) return false;

                it
            = fence->next->element;
                
            return true;
            }

            template
            <typename Type>
            bool LList<Type>::insert( const Type& item )
            {
                fence
            ->next= new CLink<Type>( item, fence->next );

                
            if( tail== fence ) tail= fence->next;
                rightcnt
            ++;

                
            return true;
            }

            template
            <typename Type>
            bool LList<Type>::append( Type const& Item )
            {
                tail
            = tail->next= new CLink<Type>( Item, NULL );
                rightcnt
            ++;

                
            return true;
            }

            template
            <typename Type>
            bool LList<Type>::remove( Type& it )
            {
                
            if( fence->next== NULL ) return false;

                it
            = fence->next->element;

                CLink
            <Type>* ltemp= fence->next;
                fence
            ->next= ltemp->next;
                
            if( tail== ltemp ) tail= fence;

                delete ltemp;
                rightcnt
            --;

                
            return true;
            }

            template
            <typename Type>
            void LList<Type>::pre()
            {
                CLink
            <Type>* temp= head;

                
            if( fence== head ) return;
                
            while( temp->next!= fence ) temp= temp->next;
                fence
            = temp;

                leftcnt
            --, rightcnt++;
            }

            template
            <typename Type>
            bool LList<Type>::setPos(  int pos )
            {
                
            if( pos< 0 || pos> rightcnt+ leftcnt ) return false;

                fence
            = head;
                
            forint i= 0; i< pos; ++i ) fence= fence->next;

                
            return true;
            }

            template
            <typename Type>
            bool LList<Type>::setvalue( int pos, Type Item )
            {
                
            if( pos< 0 || pos> rightcnt+ leftcnt ) return false;

                fence
            = head;
                
            forint i= 0; i< pos; ++i ) fence= fence->next;

                fence
            ->element= Item;
            }

            template
            <typename Type>
            bool LList<Type>::setvalue( Type Item )
            {
                
            if( fence= head ) return false;

                fence
            ->element= Item;
                
            return true;
            }


            template
            <typename Type>
            int LList<Type>::length() const
            {
                
            return rightcnt+ leftcnt;
            }

            template
            <typename Type>
            bool LList<Type>::empty() const
            {
                
            return rightcnt+ leftcnt== 0;
            }

            template
            <typename Type>
            bool LList<Type>::find( Type const& Item )
            {
                CLink
            <Type>* temp;

                
            for( temp= head; temp; temp= temp->next )
                    
            if( temp->element== Item ) return true;

                
            return false;
            }


            template
            <typename Type>
            void LList<Type>::print() const
            {
                CLink
            <Type>* temp= head;

                cout 
            << "";
                
            while( temp!= fence )
                {
                    cout 
            << temp->next->element << " ";
                    temp
            = temp->next;
                }

                cout 
            << "";
                
            while( temp->next!= NULL )
                {
                    cout 
            << temp->next->element << ' ';
                    temp
            = temp->next;
                }

                cout 
            << "" << endl;
            }


            #endif

            posted on 2009-03-15 10:47 Darren 閱讀(905) 評論(2)  編輯 收藏 引用

            評論:
            # re: 線性表抽象數據結構(c++模板實現) 2009-03-21 00:46 | reason
            你這blog全是代碼啊,很強大  回復  更多評論
              
            # re: 線性表抽象數據結構(c++模板實現) 2009-03-21 20:44 | Darren
            @reason
            說白了就是保存代碼用的
            呵呵  回復  更多評論
              
            久久天天躁狠狠躁夜夜不卡| 久久99国产精品久久| 青青青伊人色综合久久| 久久午夜伦鲁片免费无码| 久久99热这里只频精品6| 久久无码人妻精品一区二区三区| 99久久无码一区人妻| 91精品国产高清久久久久久国产嫩草| 国产99精品久久| 国产精品免费福利久久| 老司机国内精品久久久久| 久久综合九色综合精品| 亚洲一区中文字幕久久| 久久国产精品免费一区| 久久久受www免费人成| 婷婷久久综合九色综合绿巨人| 亚洲欧美久久久久9999| 国产成人精品综合久久久久| 日韩精品久久无码人妻中文字幕| 99久久精品午夜一区二区| 久久久久四虎国产精品| 久久97久久97精品免视看| 亚洲精品无码久久久| 午夜精品久久久久久毛片| 久久国产精品成人免费| 久久久久国产精品麻豆AR影院| 一级做a爰片久久毛片毛片| 日本人妻丰满熟妇久久久久久| 精品久久777| 日韩欧美亚洲国产精品字幕久久久| 久久成人国产精品免费软件| 国产产无码乱码精品久久鸭| 欧美性大战久久久久久| 欧美午夜精品久久久久免费视| 天天久久狠狠色综合| 久久久久亚洲av综合波多野结衣| 久久精品国产亚洲AV无码偷窥| 久久久91人妻无码精品蜜桃HD| 色婷婷综合久久久久中文一区二区| 国产精品久久久天天影视香蕉 | 久久精品国产精品亜洲毛片|