青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Lyt
posts - 16,comments - 61,trackbacks - 0

發(fā)現(xiàn)這里被我荒廢了很久,自動腸粉--

最近在湊數(shù)據(jù)結構,發(fā)現(xiàn)要湊個稍微好看點的代碼難度好大,模仿了.NET改了自己以前的結構,憋了一天終于把可擴展的List折騰出來了

比較怪異的是迭代器iterator,怎么看怎么別扭,暫時先湊合著吧

IIterator.h

        template<typename _Type>
        
class IIterator    //迭代器
        {
        
protected:
            _Type Current;

        
public:
            
virtual ~IIterator()
            
{
            }


            
virtual _Type CurrentItem()const=0;        //Current是否有效
            virtual void First()=0;                    //Current移到首位
            virtual bool IsDone()const=0;            //Current是否到達末尾,true的時候CurrentItem()失效
            virtual bool IsFirst()const=0;            //Current是否在首位
            virtual bool IsLast()const=0;            //Current是否到達末尾,ture的時候CurrentItem()有效
            virtual bool IsAvailable()const=0;        //Current是否有效
            virtual void MoveNext()=0;                //Current移到下一位置
        }
;

        template
<typename _Type>
        
class IForwordIterator : public IIterator<_Type>    //單向迭代器
        {
        
public:
            
virtual ~IForwordIterator()
            
{
            }


            
virtual _Type CurrentItem()const=0;        //Current是否有效
            virtual void First()=0;                    //Current移到首位
            virtual bool IsDone()const=0;            //Current是否到達末尾,true的時候CurrentItem()失效
            virtual bool IsFirst()const=0;            //Current是否在首位
            virtual bool IsLast()const=0;            //Current是否到達末尾,ture的時候CurrentItem()有效
            virtual bool IsAvailable()const=0;        //Current是否有效
            virtual void MoveNext()=0;                //Current移到下一位置
        }
;

        template
<typename _Type>
        
class IBidirectionalIterator : public IIterator<_Type>    //雙向迭代器
        {
        
public:
            
virtual ~IBidirectionalIterator()
            
{
            }


            
virtual _Type CurrentItem()const=0;        //Current是否有效
            virtual void First()=0;                    //Current移到首位
            virtual bool IsDone()const=0;            //Current是否到達末尾,true的時候CurrentItem()失效
            virtual bool IsFirst()const=0;            //Current是否在首位
            virtual bool IsLast()const=0;            //Current是否到達末尾,ture的時候CurrentItem()有效
            virtual bool IsAvailable()const=0;        //Current是否有效
            virtual void MoveNext()=0;                //Current移到下一位置

            
virtual void MovePrev()=0;                //Current移到前一位置
        }
;

        template
<typename _Type>
        
class IRandomIterator : public IIterator<_Type>    //隨機迭代器
        {
        
public:
            
virtual ~IRandomIterator()
            
{
            }


            
virtual _Type CurrentItem()const=0;        //Current是否有效
            virtual void First()=0;                    //Current移到首位
            virtual bool IsDone()const=0;            //Current是否到達末尾,true的時候CurrentItem()失效
            virtual bool IsFirst()const=0;            //Current是否在首位
            virtual bool IsLast()const=0;            //Current是否到達末尾,ture的時候CurrentItem()有效
            virtual bool IsAvailable()const=0;        //Current是否有效
            virtual void MoveNext()=0;                //Current移到下一位置
            
            
virtual void MovePrev()=0;                //Current移到前一位置
            virtual void SkipPrev(const int n)=0;    //Current前移n位
            virtual void SkipNext(const int n)=0;    //Current后移n位
        }
;

        template
<typename _Type>
        
class IIterative    //可迭代的
        {
        
public:
            
virtual ~IIterative()
            
{
            }


            
virtual AutoPtr<IIterator<_Type>> CreateIterator()const=0;    //返回迭代器
        }
;

ListIterator

        template<typename _Type>
        
class ListIterator : public IRandomIterator<_Type>        //List迭代器
        {
        
public:
            
const List<_Type>* Data;
            
int Index;

            ListIterator(
const List<_Type>* Object)
            
{
                
if (!Object || Object->IsEmpty()) throw L"List迭代器初始化出錯";
                
else
                
{
                    Data
=Object;
                    Index
=0;
                }

            }


            ListIterator(
const ListIterator<_Type>& Object)
            
{
                Data
=Object.Data;
                Index
=Object.Index;
                Current
=Object.Current;
            }


            
virtual ~ListIterator()
            
{
            }


            
virtual _Type CurrentItem()const        //Current是否有效
            {
                
if (IsAvailable()) return Current;
                
else throw L"非法訪問當前元素";
            }


            
virtual void First()                    //Current移到首位
            {
                
if (Data->IsEmpty()) throw L"List為空";
                
else
                
{
                    Index
=0;
                    Current
=Data->operator [](0);
                }

            }


            
virtual bool IsDone()const                //Current是否到達末尾,true的時候CurrentItem()失效
            {
                
return Index>=Data->GetCount();
            }


            
virtual bool IsFirst()const                //Current是否在首位
            {
                
return Index==0;
            }


            
virtual bool IsLast()const                //Current是否到達末尾,ture的時候CurrentItem()有效
            {
                
return Index==Data->GetCount()-1;
            }


            
virtual bool IsAvailable()const            //Current是否有效
            {
                
return (Index>=0 && Index<=Data->GetCount()-1);
            }


            
virtual void MoveNext()                    //Current移到下一位置
            {
                
++Index;
                
if (IsAvailable()) Current=Data->operator [](Index);
            }

            
            
virtual void MovePrev()                    //Current移到前一位置
            {
                
--Index;
                
if (IsAvailable()) Current=Data->operator [](Index);
            }


            
virtual void SkipPrev(const int n)        //Current前移n位
            {
                Index
-=n;
                
if (IsAvailable()) Current=Data->operator [](Index);
            }


            
virtual void SkipNext(const int n)        //Current后移n位
            {
                Index
+=n;
                
if (IsAvailable()) Current=Data->operator [](Index);
            }

        }
;

 

ICollecion.h

        template<typename _Type>
        
class ICollection : public IIterative<_Type>
        
{
        
protected:
            
int Count;            //元素個數(shù)

        
public:
            
virtual ~ICollection()
            
{
            }


            
virtual AutoPtr<IIterator<_Type>> CreateIterator()const=0;    //返回迭代器,繼承自IIterative

            
virtual const int GetCount()const=0;                    //返回元素個數(shù)
            virtual bool IsEmpty()const=0;                            //是否為空
            virtual bool Add(const _Type& Object)=0;                        //從尾部添加元素
            virtual void Clear()=0;                                    //刪除所有元素
            virtual bool Contains(const _Type& Object)const=0;                //是否包含指定元素
            virtual bool Remove(const _Type& Object)=0;                    //刪除指定元素,若有多個,則刪除第一個
        }
;

IList.h

        template<typename _Type>
        
class IList : public ICollection<_Type>
        
{
        
public:
            
virtual ~IList()
            
{
            }


            
virtual AutoPtr<IIterator<_Type>> CreateIterator()const=0;        //返回迭代器,繼承自IIterative
            virtual const int GetCount()const=0;                            //返回元素個數(shù),繼承自ICollection
            virtual bool IsEmpty()const=0;                                    //是否為空,繼承自ICollection
            virtual bool Add(const _Type& Object)=0;                        //從尾部添加元素,繼承自ICollection
            virtual void Clear()=0;                                            //刪除所有元素,繼承自ICollection
            virtual bool Contains(const _Type& Object)const=0;                //是否包含指定元素,繼承自ICollection
            virtual bool Remove(const _Type& Object)=0;                        //刪除指定元素,若有多個,則刪除第一個,繼承自ICollection

            
virtual int IndexOf(const _Type& Object)const=0;                //返回指定元素所在位置,若不存在返回-1,若有多個,返回第一個
            virtual bool Insert(const int Index, const _Type& Object)=0;    //在指定位置插入指定元素
            virtual bool RemoveAt(const int Index)=0;                        //在指定位置刪除元素
        }
;
List.h
        template<typename _Type>
        
class List : public IList<_Type>
        
{
        
private:
            
bool Grow();                                                        //如果Capacity有增大,則返回真
            void Update();                                                        //Capacity增大導致Items需要更新
    
        
protected:
            _Type
* Items;
            
int Capacity;                                                        //List可容納元素個數(shù)
            static const int GRAW_CAPACITY;                                        //List每次增大的容量

        
public:
            
bool IsFixedSize;                                                    //List大小是否固定

            List(
const bool Fixed=false);
            List(
const int ObjectCount, const bool Fixed=false);
            List(
const List<_Type>& Object);

            
virtual ~List();

            
virtual AutoPtr<IIterator<_Type>> CreateIterator()const;            //返回迭代器,繼承自IIterative
            virtual void Clear();                                                //刪除所有元素,繼承自ICollection
            virtual const int GetCount()const;                                    //返回元素個數(shù),繼承自ICollection
            virtual int IndexOf(const _Type& Object)const;                        //返回指定元素所在位置,若不存在返回-1,繼承自IList
            virtual int LastIndexOf(const _Type& Object)const                    //返回指定元素所在位置,若不存在返回-1,若有多個,返回最后一個
            virtual bool IsEmpty()const;                                        //是否為空,繼承自ICollection
            virtual bool Add(const _Type& Object);                                //從List尾部添加元素,繼承自ICollection
            virtual bool Add(const List<_Type>& Object);                        //在List末尾添加列表
            virtual bool Contains(const _Type& Object)const;                    //是否包含指定元素,繼承自ICollection
            virtual bool Remove(const _Type& Object);                            //刪除指定元素,若有多個,則刪除第一個,繼承自ICollection
            virtual bool Remove(const int Index, const int n);                    //從Index開始刪除n個元素
            virtual bool RemoveAt(const int Index);                                //在指定位置刪除元素,繼承自IList
            virtual bool Insert(const int Index, const _Type& Object);            //在指定位置插入指定元素,繼承自IList
            virtual bool Insert(const int Index, const List<_Type>& Object);    //從Index開始插入Object
            virtual List<_Type> Sub(const int Index, const int n)const;            //從Index開始取n個元素
            virtual List<_Type> Left(const int n)const;                            //取左邊n個元素
            virtual List<_Type> Right(const int n)const;                        //取右邊n個元素
            _Type operator[](const int Index)const;
            _Type
& operator[](const int Index);
            List
<_Type> operator=(const List<_Type>& Object);
            
bool operator==(const List<_Type>& Object)const;
            
bool operator!=(const List<_Type>& Object)const;
            List
<_Type> operator+(const _Type& Object)const;
            List
<_Type> operator+(const List<_Type>& Object)const;
        }
;

例子:

void Print(AutoPtr<ListIterator<int>> Iterator)
{
    
for (Iterator->First(); !Iterator->IsDone(); Iterator->MoveNext()) cout<<Iterator->CurrentItem()<<" ";
    cout
<<endl;
}


void main(int argc , char* argv[])
{
    setlocale(LC_ALL,
"chs");
    List
<int> A(1);
    A[
0]=1;
    AutoPtr
<ListIterator<int>> Iterator=A.CreateIterator();
    Print(Iterator);
    A.Add(
2);
    cout
<<"After A.Add(2) : ";
    Print(Iterator);
    
if (A.Contains(1)) cout<<"A contains 1"<<endl;
    
if (!A.Contains(3)) cout<<"A doesn't contain 3"<<endl;
    cout
<<"index of 1 is "<<A.IndexOf(1)<<endl;
    cout
<<"index of 3 is "<<A.IndexOf(3)<<endl;
    A.Insert(
0,0);
    cout
<<"After A.Insert(0,0) : ";
    Print(Iterator);
    A.Insert(
1,3);
    cout
<<"After A.Insert(1,3) : ";
    Print(Iterator);
    A.RemoveAt(
1);
    cout
<<"After A.RemoveAt(1) : ";
    Print(Iterator);
    List
<int> B=A.Right(2);
    A.Insert(
1, B);
    cout
<<"After B=A.Right(2); A.Insert(1, B) : ";
    Print(Iterator);
    A
=A.Sub(1,3);
    cout
<<"After A=A.Sub(1,3) : ";
    Print(Iterator);
    B
=A.ToArray();
    A
=A+B;
    cout
<<"After B=A.ToArray(); A=A+B : ";
    Print(Iterator);
    cout
<<"last index of 2 is "<<A.LastIndexOf(2)<<endl;
    _getch();
}

結果如下:

1
After A.Add(2) : 1 2
A contains 1
A doesn't contain 3
index of 1 is 0
index of 3 is -1
After A.Insert(0,0) : 0 1 2
After A.Insert(1,3) : 0 3 1 2
After A.RemoveAt(1) : 0 1 2
After B=A.Right(2); A.Insert(1, B) : 0 1 2 1 2
After A=A.Sub(1,3) : 1 2 1
After B=A.ToArray(); A=A+B : 1 2 1 1 2 1
last index of 2 is 4

 

 

C#在用delegate的確很爽,無奈C++沒得爽,本來很天真地想實現(xiàn)一下功能

template<typename _Type>
class List : public IList<_Type>
{
  template
<typename T>
  typedef 
bool Predicate(T& Object);

  
bool Exists(Predicate<_Type> Match)
  {
    
if (Match(*this)) return true;
    
else return false;
  }
};

 網(wǎng)上搜了下,才發(fā)現(xiàn)C++沒有這個特性,delegate暫時湊不出來,于是折騰了個難看的辦法,沒想到還是不行,至今不知道為啥

template<typename _Type>
class List : public IList<_Type>
{
  
bool Exists ((bool(*Predicate)(List<_Type>& Object)) Match)
  {
    
if (Match(*this)) return true;
    
else return false;
  }
};

 

歡迎大家來噴哈~

posted on 2009-09-23 11:20 Lyt 閱讀(1986) 評論(5)  編輯 收藏 引用 所屬分類: 數(shù)據(jù)結構

FeedBack:
# re: Collection::List
2009-09-23 14:56 | OwnWaterloo
如果以GP而非OOP的方式構建集合,你會發(fā)現(xiàn)C++的template即使沒有delegate也會很爽。C#沒得這么爽。   回復  更多評論
  
# re: Collection::List
2009-09-23 18:30 | 陳梓瀚(vczh)
@OwnWaterloo
我的VL++2.0推掉重寫,最近再寫3.0,實踐了一下同時GP+OOP,最后發(fā)現(xiàn)可行,而且我也實現(xiàn)了delegate,將linq搬過來了。  回復  更多評論
  
# re: Collection::List
2009-09-23 18:35 | OwnWaterloo
@陳梓瀚(vczh)
支持推倒……  回復  更多評論
  
# re: Collection::List
2009-09-24 12:15 | 陳梓瀚(vczh)
@OwnWaterloo
原來同是宅人……  回復  更多評論
  
# re: Collection::List[未登錄]
2009-09-28 11:21 | a
不用GP, 很多情況下都可以忽略Iterator,很多人用it無非是rbtree。我就喜歡直接用int遍歷hash(directory), vector, list之類的。。  回復  更多評論
  
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲主播在线播放| 欧美激情一区二区三区| 日韩午夜激情av| 久久久亚洲午夜电影| 欧美亚洲日本网站| 欧美深夜影院| 日韩香蕉视频| 亚洲美女一区| 免费观看国产成人| 久久午夜羞羞影院免费观看| 国产精品区一区二区三区| 亚洲精品一二三| 夜夜嗨av色一区二区不卡| 欧美成人一二三| 亚洲春色另类小说| 狠色狠色综合久久| 久久精品99国产精品酒店日本| 香蕉乱码成人久久天堂爱免费| 国产精品国产一区二区| 日韩亚洲欧美高清| 亚洲一级在线| 欧美午夜无遮挡| 在线亚洲免费视频| 亚洲女爱视频在线| 国产精品免费电影| 亚洲欧美激情一区二区| 久久成人亚洲| 国自产拍偷拍福利精品免费一| 欧美影片第一页| 久久久亚洲综合| 亚洲国产99| 欧美电影免费观看高清| 亚洲精品看片| 亚洲欧美成人综合| 国产欧美日韩精品一区| 羞羞漫画18久久大片| 久久综合色88| 亚洲黄色小视频| 欧美韩国在线| 亚洲一区精品视频| 久久中文字幕导航| 亚洲国产精品久久久久秋霞不卡 | 99国产精品| 欧美另类极品videosbest最新版本| 亚洲精品一区二区在线| 性欧美xxxx视频在线观看| 国产亚洲欧美色| 另类春色校园亚洲| 日韩视频免费在线观看| 欧美一区二区三区日韩| 尤物视频一区二区| 欧美三区在线| 久久精品一区二区| 最新精品在线| 欧美一区二区日韩| 在线观看日韩欧美| 欧美视频一区二区三区…| 久久国产精品高清| 亚洲免费观看高清在线观看 | 一区二区久久| 久久一日本道色综合久久| 亚洲精品黄网在线观看| 国产精品视频精品视频| 久久久蜜桃精品| 99热这里只有精品8| 久久综合网色—综合色88| 一区二区三区国产盗摄| 国内伊人久久久久久网站视频 | 亚洲毛片av在线| 国产精品影院在线观看| 欧美成人免费视频| 久久精品中文字幕一区二区三区| 99国产成+人+综合+亚洲欧美| 久久九九国产精品怡红院| 一本一道久久综合狠狠老精东影业 | 日韩视频久久| 欧美成人免费在线| 亚洲欧美区自拍先锋| 亚洲欧洲美洲综合色网| 国产亚洲精品久久久久婷婷瑜伽| 欧美风情在线观看| 久久久久久久综合| 欧美一区二区三区在线观看视频| 日韩午夜电影av| 亚洲国产精品激情在线观看| 久久午夜电影| 久久久久一区二区三区四区| 亚洲一区二区三区涩| 亚洲人成亚洲人成在线观看| 精品1区2区3区4区| 国产亚洲欧美另类一区二区三区| 国产精品免费一区二区三区在线观看 | 欧美女人交a| 欧美不卡视频一区发布| 久久免费黄色| 久久中文在线| 午夜在线a亚洲v天堂网2018| 99国产精品久久久久久久| 亚洲国产精品一区二区久| 欧美成人午夜77777| 久久综合激情| 麻豆freexxxx性91精品| 久久亚洲精品中文字幕冲田杏梨| 久久精品国产欧美激情| 久久久午夜电影| 久久综合网络一区二区| 麻豆精品一区二区综合av | 亚洲经典自拍| 亚洲精品乱码久久久久久| 91久久精品国产91久久性色| 亚洲欧洲偷拍精品| 日韩视频在线你懂得| 99国产一区| 亚洲欧美激情视频在线观看一区二区三区| 99亚洲一区二区| 亚洲一区在线播放| 欧美在线视频不卡| 久久久免费精品| 美腿丝袜亚洲色图| 欧美精品亚洲精品| 欧美视频1区| 国产视频精品va久久久久久| 国产综合网站| 91久久精品一区二区别| 99riav国产精品| 亚洲一区网站| 久久9热精品视频| 蜜臀99久久精品久久久久久软件 | 久久视频在线免费观看| 猛男gaygay欧美视频| 欧美大片在线观看一区| 亚洲区一区二| 亚洲自啪免费| 久久亚洲精品欧美| 欧美不卡一卡二卡免费版| 欧美体内谢she精2性欧美| 国内精品久久久久伊人av| 亚洲精品欧美精品| 欧美一级视频| 亚洲国产日韩欧美| 亚洲欧美日韩国产| 免费成人av在线| 欧美性一二三区| 亚洲大胆美女视频| 亚洲午夜激情在线| 麻豆精品视频在线观看| 亚洲视频日本| 免费的成人av| 国产女人水真多18毛片18精品视频| 伊大人香蕉综合8在线视| 亚洲午夜小视频| 欧美1区2区视频| 亚洲专区一区二区三区| 欧美成人一区在线| 国产一区二区主播在线 | 在线观看视频一区二区| 亚洲综合电影一区二区三区| 麻豆精品视频在线观看视频| 亚洲午夜精品| 欧美精品麻豆| 亚洲第一精品影视| 久久激情中文| 亚洲一区久久| 国产精品扒开腿做爽爽爽视频| 亚洲国产婷婷| 另类天堂av| 篠田优中文在线播放第一区| 欧美日本精品| 亚洲免费观看高清完整版在线观看熊| 久久成人18免费观看| 一区二区激情| 欧美日韩一区精品| 日韩午夜三级在线| 欧美高清在线播放| 久久久视频精品| 国产亚洲精品久久久久婷婷瑜伽| 国产精品99久久99久久久二8 | 欧美日韩国产综合视频在线观看| 黄色国产精品| 久久精品视频在线播放| 这里只有精品在线播放| 欧美日韩国产91| 一区二区三区免费网站| 亚洲国产日韩在线| 欧美激情国产高清| 99精品国产高清一区二区 | 91久久精品国产91性色tv| 久久久久久久网| 一区国产精品| 久久免费少妇高潮久久精品99| 中国女人久久久| 国产精品美女久久久久aⅴ国产馆| 一本大道久久a久久精品综合| 亚洲黄色毛片| 欧美激情网友自拍| 99精品视频一区二区三区| 亚洲大片一区二区三区| 牛夜精品久久久久久久99黑人| 亚洲精品你懂的| 亚洲精品一区二区三区蜜桃久|