simchain.h
来自「模拟指针,使用固定的数组模拟指针的内存分配」· C头文件 代码 · 共 58 行
H
58 行
#ifndef _SIMCHAIN_H
#define _SIMCHAIN_H
#include <iostream>
using namespace std;
template <typename T> class CSimSpace;
template <typename T> class CSimChain;
template <typename T>
class CSimNode
{
friend class CSimSpace<T>;
friend class CSimChain<T>;
T data;
int link;
};
template<typename T>
class CSimSpace
{
friend class CSimChain<T>;
public:
CSimSpace(int MaxSpaceSize=100);
~CSimSpace();
int Allocate();
void DeAllocate(int &i);
private:
int NumberOfNode;
int first;
CSimNode<T> *node;
};
template<typename T>
class CSimChain
{
public:
CSimChain(){first=-1;}
~CSimChain(){Destroy();}
void FillElem(T temp[],int len);
void Destroy();
int Length() const;
bool Find(int k,T &x) const;
int Search(const T&x) const;
CSimChain<T>& Delete(int k,T &x);
CSimChain<T>& Insert(int k,const T &x);
void Output(ostream &out)const;
private:
int first;
static CSimSpace<T> S;
};
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?