这个文件是设计模式中可能要用到的数据结构,将它根据需要补全,在后绪的学习中将会根据需要慢慢补,不断更新中。 // BasicClass.h:interfacefortheBasicClassclass. // /**/ // #if !defined(AFX_BASICCLASS_H__459C19CB_0047_4A50_855E_B7FDCFC6F3B0__INCLUDED_) #define AFX_BASICCLASS_H__459C19CB_0047_4A50_855E_B7FDCFC6F3B0__INCLUDED_ #if _MSC_VER>1000 #pragma once #endif // _MSC_VER>1000 // #include < iostream > /**/ /*usingnamespacestd::;*/ using std::cout; using std::ostream; using std::istream; // #include<iostream.h> // std::list<int> #define DEFAULT_LIST_CAPACITY1000 template < class T > class List;template < class T > class ListNode // T便是一个指针 ... {public:friendclassList<T>;ListNode()...{_data=NULL;_next=NULL;}ListNode(constT&item);ListNode&operator=(constListNode&);T_data;ListNode<T>*_next;} ;template < class T > class List // T便是一个指针 ... {public:List(longsize=DEFAULT_LIST_CAPACITY)...{_last=NULL;_first=NULL,_current=NULL;_size=0;}List(List&list);~List()...{}List&operator=(constList&);longCount()const...{return_size;}T&Get(longindex)const...{ListNode<T>*p=_first;for(inti=0;i<index;i++)...{p=p->_next;}returnp->_data;}T&First()const...{return_first->_data;}ListNode<T>*FirstPoint()...{return_first;}T&Last()const...{return_last->_data;}boolIncludes(constT&data)const...{ListNode<T>*p=_first;while(p!=NULL)...{if(data==p->_data)...{returntrue;}}returnfalse;}voidAppend(constT&data)...{ListNode<T>*p=newListNode<T>;if(_current==NULL)...{_current=p;_current->_data=data;if(_first==NULL)...{//空链表_first=_last=_current;}}else...{p->_next=_current->_next;_current->_next=p;_current=_current->_next;//将当前指针指向插入的节点if(_current->_next==NULL)...{//如果是在链尾加,_last=_current;}}}//voidPrepend(constT&data)//{//ListNode<T>*p=newListNode<T>;////if(_current==NULL)//{////}//}voidRemove(constT&data)...{}voidRemoveLast();voidRemoveFirst();voidRemoveAll();T&Top()const;voidPush(constT&);T&Pop();ListNode<T>*_first;ListNode<T>*_last;ListNode<T>*_current;int_size;} ;template < class T > class Iterator ... {friendclassList<T>;public:virtualvoidFirst()=0;virtualvoidNext()=0;virtualboolIsDone()const=0;virtualTCurrentItem()const=0;} ;template < class T > // ListNode<equment*>* class ListIterator: public Iterator < T > ... {public:T_ptr;T_first;ListIterator()...{_ptr=0;_first=0;}ListIterator(Talist)...{_ptr=alist;_first=alist;}//ListIterator(constListIterator<T>aList&);virtualvoidFirst()...{_ptr=_first;}virtualvoidNext()...{_ptr=_ptr->_next;}virtualboolIsDone()const...{return_ptr!=NULL;}virtualTCurrentItem()const...{return_ptr;}} ;typedef float Coord; class Point ... {public:staticconstPointZero;Point(Coordx=0.0,Coordy=0.0);CoordX()const;//得到x值CoordY()const;voidX(Coordx);//设置x值voidY(Coordy);Pointoperator+(constPoint&);Pointoperator-(constPoint&);Pointoperator*(constPoint&);Pointoperator/(constPoint&);voidoperator+=(constPoint&);voidoperator-=(constPoint&);voidoperator*=(constPoint&);voidoperator/=(constPoint&);booloperator==(constPoint&);booloperator!=(constPoint&);friendostream&operator<<(ostream&,constPoint&);friendistream&operator>>(istream&,Point&);private:Coordm_x;Coordm_y;} ; class Rect