设计模式中的相关基础类文件

这个文件是设计模式中可能要用到的数据结构,将它根据需要补全,在后绪的学习中将会根据需要慢慢补,不断更新中。

// 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:
friend
classList<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
... {
friend
classList<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);

Point
operator+(constPoint&);
Point
operator-(constPoint&);
Point
operator*(constPoint&);
Point
operator/(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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值