#include <assert.h>
template <class eminu>
class list
{
private:
int curr_len;
eminu *shuzu;
eminu xxx;
const int m_Maxlen;
public:
list(const int maxlen);//创建maxlen个数据的数组
~list();
void Clear();//清空
void Putinto(eminu tmp);//写入数据
void Insert(eminu tmp,int pos);//在POS处插入
void display();//显示目前的数据内容
void Delete(int pos); //删除POS处数据
bool Isfull();//判断是否为满
bool Isempty();//判断是否为空
eminu Get(int i);//截取I处数据
};
template <class eminu>
list<eminu>::list(const int maxlen=0)
{
m_Maxlen=maxlen;
shuzu=new eminu[maxlen];
curr_len=0;
}
template <class eminu>
list<eminu>::~list()
{
delete []shuzu;
}
template <class eminu>
void list<eminu>::Clear()
{
for(int i=0;i<curr_len;i++)
{
shuzu[i]=0;
}
}
template <class eminu>
void list<eminu>::Putinto(eminu tmp)
{
shuzu[curr_len]=tmp;
curr_len++;
}
template <class eminu>
void list<eminu>::Insert(eminu tmp,int pos)
{
assert(pos>=1&&pos<=curr_len&&!Isfull());
for(int here=m_Maxlen;here>curr_len;here--)
{
shuzu[here]=shuzu[here-1];
}
shuzu[pos]=tmp;
}
template <class eminu>
void list<eminu>::display()
{
for(int i=0;i<curr_len;i++)
{
cout<<shuzu[i]<<" ";
}
cout<<endl;
}
template <class eminu>
eminu list::Get(int pos)
{
assert(pos<=curr_len&&pos>=0);
return shuzu[pos];
}
template <class eminu>
bool list<eminu>::Isfull()
{
return curr_len==m_Maxlen;
}
template <class eminu>
bool list<eminu>::Isempty()
{
return curr_len==0;
}
template <class eminu>
void list<eminu>::Delete(int pos)
{
assert(!Isempty()&&pos<=curr_len);
for(int i=pos-1;i<curr_len;i++)
{
shuzu[i]=shuzu[i+1];
}
}
main,cpp:
#include "list.h"
int main()
{
list<int> text(5);
text.Putinto(1);
text.display();
~list<int> text();
return 0;
}
我现在正在上上机课,有个错误老师和我都没看出来
大家帮忙看一下