65,187
社区成员




#ifndef TEST_H
#define TEST_H
#include <iostream>
using namespace std;
//----------------------顺序表的类声明----------------------------//
template <class T> class SeqList
{
private:
T *data; //存放数组
int maxSize; //顺序表的大小
int last; //当前已存储的顺序表的最后一个位置(从0开始0)
public:
SeqList(); //默认构造函数
SeqList(int maxS); //构造长度为maxSize的顺序表
//SeqList<T> operator = (SeqList<T> &L); //表整体赋值
~SeqList(); //析构函数
void input(); //输入函数
void output(); //输出函数
bool insert(int i, T &x); //插入x到第i个表项之后
bool remove(int i, T &x); //删除第i个表项,通过x返回表项的值
bool IsEmpty(); //判断顺序表是否为空
bool IsFull(); //判断顺序表是否已满
bool getData(int i, T &x); //取出第i个表项的值
int Locate(int i); //定位第i个元素,函数返回表项序号
};
template<class T> SeqList<T>::SeqList(int maxS)
{
maxSize = maxS;
}
template<class T> SeqList<T>::~SeqList()
{
}
template<class T> SeqList<T>::input()
{
for(int i=0; i<maxSize-5; i++)
cin >> data[i];
last = maxSize-5;
}
template<class T> SeqList<T>::output()
{
for(int i=0; i<maxSize; i++)
cout << data[i] << '\t';
cout << endl;
}
template<class T> SeqList<T>::insert(int i, T &x)
{
maxSize++;
int n=maxSize
for(; n>i; n--)
data[n] = data[n-1];
data[n] = x;
}
template<class T> SeqList<T>::remove(int i, T &x)
{
int n=i;
for(; n<maxSize; n++)
data[n] = data[n+1];
data[maxSize] = 0;
maxSize--;
}
template<class T> SeqList<T>::IsEmpty()
{
if(maxSize<0)
return true;
else
return false;
}
template<class T> SeqList<T>::IsFull()
{
if(maxSize>=10)
return true;
else
return false;
}
template<class T> SeqList<T>::getData(int i, T &x)
{
if(i>0 && i<=maxSize+1)
{
x = data[i-1];
return true;
}
else
return false;
}
template<class T> SeqList<T>::Locate(int i)
{
if(i>0 && i<=maxSize+1)
return data[i+1];
else
return 0;
}
#endif
1>c:\users\administrator\desktop\test\test\test.h(43): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(50): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(59): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(68): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(76): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(84): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(95): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\test\test\test.h(103): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
template<class T>
int SeqList<T>::Locate(int i) // 返回值int
{
if(i>0 && i<=maxSize+1)
return data[i+1]; // 这个好像是返回T
else
return 0;
}