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

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

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

最近在湊數(shù)據(jù)結(jié)構(gòu),發(fā)現(xiàn)要湊個稍微好看點(diǎn)的代碼難度好大,模仿了.NET改了自己以前的結(jié)構(gòu),憋了一天終于把可擴(kuò)展的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是否到達(dá)末尾,true的時候CurrentItem()失效
            virtual bool IsFirst()const=0;            //Current是否在首位
            virtual bool IsLast()const=0;            //Current是否到達(dá)末尾,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是否到達(dá)末尾,true的時候CurrentItem()失效
            virtual bool IsFirst()const=0;            //Current是否在首位
            virtual bool IsLast()const=0;            //Current是否到達(dá)末尾,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是否到達(dá)末尾,true的時候CurrentItem()失效
            virtual bool IsFirst()const=0;            //Current是否在首位
            virtual bool IsLast()const=0;            //Current是否到達(dá)末尾,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>    //隨機(jī)迭代器
        {
        
public:
            
virtual ~IRandomIterator()
            
{
            }


            
virtual _Type CurrentItem()const=0;        //Current是否有效
            virtual void First()=0;                    //Current移到首位
            virtual bool IsDone()const=0;            //Current是否到達(dá)末尾,true的時候CurrentItem()失效
            virtual bool IsFirst()const=0;            //Current是否在首位
            virtual bool IsLast()const=0;            //Current是否到達(dá)末尾,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"非法訪問當(dāng)前元素";
            }


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

            }


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


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


            
virtual bool IsLast()const                //Current是否到達(dá)末尾,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增大導(dǎo)致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();
}

結(jié)果如下:

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 閱讀(1998) 評論(5)  編輯 收藏 引用 所屬分類: 數(shù)據(jù)結(jié)構(gòu)

FeedBack:
# re: Collection::List
2009-09-23 14:56 | OwnWaterloo
如果以GP而非OOP的方式構(gòu)建集合,你會發(fā)現(xiàn)C++的template即使沒有delegate也會很爽。C#沒得這么爽。   回復(fù)  更多評論
  
# re: Collection::List
2009-09-23 18:30 | 陳梓瀚(vczh)
@OwnWaterloo
我的VL++2.0推掉重寫,最近再寫3.0,實踐了一下同時GP+OOP,最后發(fā)現(xiàn)可行,而且我也實現(xiàn)了delegate,將linq搬過來了。  回復(fù)  更多評論
  
# re: Collection::List
2009-09-23 18:35 | OwnWaterloo
@陳梓瀚(vczh)
支持推倒……  回復(fù)  更多評論
  
# re: Collection::List
2009-09-24 12:15 | 陳梓瀚(vczh)
@OwnWaterloo
原來同是宅人……  回復(fù)  更多評論
  
# re: Collection::List[未登錄]
2009-09-28 11:21 | a
不用GP, 很多情況下都可以忽略Iterator,很多人用it無非是rbtree。我就喜歡直接用int遍歷hash(directory), vector, list之類的。。  回復(fù)  更多評論
  

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


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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一区二区三区| 欧美日韩亚洲网| 亚洲国产精品成人va在线观看| 亚洲影院在线观看| 亚洲激情综合| 久久精品视频在线看| 国产欧美日韩综合| 欧美日韩成人在线| 亚洲日韩中文字幕在线播放| 麻豆成人在线| 欧美中文在线观看| 国产视频精品网| 久久成年人视频| 亚洲黄色天堂| 伊大人香蕉综合8在线视| 久久精品国产成人| 欧美一区二区三区免费视| 国产精品天天摸av网| 性伦欧美刺激片在线观看| 亚洲一区二区成人在线观看| 国产精品xxxxx| 亚洲欧美国产精品va在线观看| 亚洲理论在线观看| 欧美午夜欧美| 午夜亚洲激情| 欧美一区二区视频97| 国外成人在线视频| 一区二区三区欧美在线| 在线亚洲自拍| 亚洲欧美日韩国产综合| 国产精品伊人日日| 久久久久在线| 久久综合国产精品台湾中文娱乐网| 一色屋精品视频在线看| 欧美国产欧美亚洲国产日韩mv天天看完整| 久久免费黄色| 欧美在线一二三| 久久精品午夜| 日韩亚洲欧美成人| 亚洲网站在线播放| 国产日韩一级二级三级| 蜜月aⅴ免费一区二区三区| 麻豆精品国产91久久久久久| 亚洲精品一区二区三区在线观看| 一本色道久久综合亚洲精品婷婷| 国产精品资源| 欧美电影免费观看| 欧美图区在线视频| 久久精品国产精品亚洲| 蜜臀久久99精品久久久画质超高清| 一区二区三区高清在线| 午夜一区二区三区不卡视频| 欧美电影打屁股sp| 欧美一区二区三区精品| 美女脱光内衣内裤视频久久网站| 亚洲特黄一级片| 久久久久高清| 亚洲综合不卡| 欧美一区二区观看视频| 欧美成人r级一区二区三区| 欧美日韩中文| 麻豆精品在线观看| 国产精品久久久久一区| 欧美大胆a视频| 国产精品网站视频| 亚洲日本一区二区| 狠狠色狠狠色综合日日五| 一本大道久久a久久精二百| 在线精品观看| 性欧美videos另类喷潮| 一区二区三区av| 亚洲欧美国产一区二区三区| 午夜激情一区| 欧美精品在线一区二区| 免费高清在线一区| 国产日本精品| 久久不见久久见免费视频1| 欧美成人午夜激情视频| 久久久亚洲国产美女国产盗摄| 欧美色视频日本高清在线观看| 欧美韩日一区| 亚洲国产精品久久久久久女王| 欧美一级专区免费大片| 久久天天综合| 亚洲激情专区| 久久综合给合| 免费一区二区三区| 激情综合中文娱乐网| 欧美在线视频播放| 久久精品国产99精品国产亚洲性色| 国产精品久久| 亚洲天堂视频在线观看| 亚洲图片欧美一区| 欧美午夜性色大片在线观看| 日韩视频专区| 亚洲一区久久久| 欧美性久久久| 亚洲视频一区在线| 亚洲欧美日韩成人| 国产精品久久影院| 亚洲小视频在线观看| 国产欧美日韩麻豆91| 亚洲免费在线观看| 欧美一区成人| 国产在线不卡精品| 久久综合久久美利坚合众国| 女同一区二区| 亚洲人成在线观看| 亚洲免费高清| 久久中文在线| 亚洲激情视频在线观看| 99精品欧美一区二区蜜桃免费| 欧美伦理视频网站| 这里只有精品丝袜| 久久精品国产亚洲5555| 在线观看一区| 欧美久久久久久| 夜夜嗨av一区二区三区四区| 欧美亚洲色图校园春色| 噜噜爱69成人精品| 欧美成人精品高清在线播放| 亚洲精品一区二区三区av| 亚洲在线中文字幕| 国产亚洲精品久久久久久| 麻豆精品精华液| av成人毛片| 伊人夜夜躁av伊人久久| 免费成人美女女| 夜夜爽夜夜爽精品视频| 久久久欧美精品| 亚洲精品欧美日韩专区| 国产精品久久久久久久久借妻 | 亚洲自拍电影| 欧美一区二区高清在线观看| 国产一区二区三区视频在线观看| 麻豆精品精华液| 国产精品99久久不卡二区| 久久久久五月天| 日韩亚洲一区二区| 国产视频久久网| 欧美劲爆第一页| 久久www成人_看片免费不卡| 亚洲片在线资源| 久久一区二区三区四区| 亚洲一区黄色| 亚洲毛片av在线| 国产在线不卡精品| 欧美色另类天堂2015| 久久婷婷久久一区二区三区| 亚洲婷婷综合久久一本伊一区| 欧美.日韩.国产.一区.二区| 国产伦精品一区二区三区照片91 | 日韩天堂av| 亚洲第一综合天堂另类专| 韩国一区二区三区在线观看| 欧美日韩大陆在线| 久久久久久黄| 亚洲欧美精品suv| 亚洲精品国产精品国自产观看浪潮 | 91久久精品www人人做人人爽| 欧美在线免费| 中文高清一区| 亚洲欧洲午夜| 一区精品在线| 国内在线观看一区二区三区| 国产精品一区三区| 国产精品国产三级国产普通话三级 | 欧美日韩一级片在线观看| 久久亚洲精品伦理| 欧美主播一区二区三区美女 久久精品人 | 国产色综合久久| 欧美午夜免费影院| 欧美日韩另类国产亚洲欧美一级| 蜜桃av噜噜一区| 久久在线91| 久久综合一区二区| 久久视频免费观看| 久久在精品线影院精品国产| 久久久国产精彩视频美女艺术照福利| 亚洲欧美视频在线观看| 亚洲欧美日韩另类精品一区二区三区| 中文精品99久久国产香蕉| 一区二区高清在线观看| 一本色道久久综合亚洲精品不卡| 一本色道久久综合一区| 亚洲天堂av高清| 午夜精品一区二区三区四区| 欧美一进一出视频| 久久全国免费视频| 老色鬼久久亚洲一区二区| 美女亚洲精品| 欧美激情精品久久久久久大尺度 | 国产欧美日韩中文字幕在线| 性色一区二区| 另类图片国产| 欧美色图天堂网| 国产视频精品免费播放| 亚洲激情网址|