共享一下
……
typedef unsigned short int UINT;
//迭代器方向
enum ITE_DIR
{
ITD_RIGHT,
ITD_DOWN ,
ITD_LEFT ,
ITD_UP
};
//矩阵扩充方向
enum AUG_DIR
{
AUG_RIGHT,
AUG_DOWN ,
AUG_LEFT ,
AUG_UP
};
//最终类对象生成元素之一
enum REC_TYPE
{
RT_LIST
,
RT_REC
,
RT_BOARD ,
RT_CUBE
};
//输出风格
enum PRINT_TYPE
{
PRT_NORMAL ,//普通输出
PRT_ADD //输出地址
};
template<typename>class CEleObj;//基础元素类
template<typename>class rec;//基础矩阵类
template<typename>class recboard;//基础矩阵板类
template<typename>class reccube;//基础矩阵块类
template<typename>class miterator;//迭代器
class POINT;//点类
template<typename T>
class DIRP
{
public:
CEleObj<T> * POINT_UP;
CEleObj<T> * POINT_DOWN;
CEleObj<T> * POINT_RIGHT;
CEleObj<T> * POINT_LEFT;
};
class POINT
{
public:
UINT x,y;
POINT(UINT _x,UINT _y):
x(_x),y(_y){}
~POINT(){}
};
template<typename T>
class CEleObj
{
public:
CEleObj(){}
CEleObj(T & rele):ele(rele){}
T get(){return ele;}
void set(T & rele){ele=rele;}
DIRP<T> DP;
private:
T ele;
};
template<typename T>
class miterator
{
CEleObj<T> * nowplace;//当前迭代指针
CEleObj<T> * phead;//头指针
POINT nowpoint;//指针当前坐标
miterator(const CEleObj<T> *);
public:
miterator(const rec<T> &);
~miterator(){}
bool next(ITE_DIR);//迭代函数
bool locate(UINT,UINT);//迭代器定位
bool locate(POINT);
};
template<typename T>
class rec
{
UINT recx,recy;
CEleObj<T> * headele;
miterator<T> * recite;
public:
friend class miterator<T>;
rec();
rec(UINT,UINT);
rec(const rec &);//拷贝构造函数
~rec();
bool insert(UINT,UINT,const T &);//插入元素
bool edit(UINT,UINT,const T &);
bool edit(POINT,const T &);
CEleObj<T> * get(UINT,UINT);//查询算法~
CEleObj<T> * get(POINT);
bool augment(rec<T> &,AUG_DIR);//扩充算法:直接对接
bool delrec();//删除整个矩阵
void print(PRINT_TYPE);//打印整个矩阵
bool _locate(UINT,UINT);//内部迭代器重定位
bool _locate(POINT);
bool _locate();
UINT getx(){return recx;}
UINT gety(){return recy;}
};
[[it] 本帖最后由 dracovash 于 2009-7-31 22:46 编辑 [/it]]