这个文件是设计模式中可能要用到的数据结构,将它根据需要补全,在后绪的学习中将会根据需要慢慢补,不断更新中。
//BasicClass.h:interfacefortheBasicClassclass.
//
/**///////////////////////////////////////////////////////////////////////
#if!defined(AFX_BASICCLASS_H__459C19CB_0047_4A50_855E_B7FDCFC6F3B0__INCLUDED_)
#defineAFX_BASICCLASS_H__459C19CB_0047_4A50_855E_B7FDCFC6F3B0__INCLUDED_
#if_MSC_VER>1000
#pragmaonce
#endif//_MSC_VER>1000
//
#include<iostream>
/**//*usingnamespacestd::;*/
usingstd::cout;
usingstd::ostream;
usingstd::istream;
//#include<iostream.h>
//std::list<int>
#defineDEFAULT_LIST_CAPACITY1000
template<classT>classList;
template<classT>classListNode//T便是一个指针
...{
public:
friendclassList<T>;
ListNode()...{_data=NULL;_next=NULL;}
ListNode(constT&item);
ListNode&operator=(constListNode&);
T_data;
ListNode<T>*_next;
};


template<classT>classList//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<classT>
classIterator
...{
friendclassList<T>;
public:
virtualvoidFirst()=0;
virtualvoidNext()=0;
virtualboolIsDone()const=0;
virtualTCurrentItem()const=0;
};
template<classT>//ListNode<equment*>*
classListIterator:publicIterator<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;
}
};

typedeffloatCoord;
classPoint...{
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;
};
classRect

被折叠的 条评论
为什么被折叠?



