?
#include <iostream>
using namespace std;
#define MAXSIZE 6
template <typename T>
class S
{
T data[MAXSIZE];
int len;
public:
//清空
int empty();
//尾插
int insert_rear(T element);
//按下标删除
int delete_index(int index);
//按下表查找
int search_index(int index);
//按下表修改
int revise_index(int index,T element);
//查看顺序表
void show();
};
//清空
template <typename T>
int S<T>::empty()
{
len=0;
data[MAXSIZE]={0};
}
//尾插
template <typename T>
int S<T>::insert_rear(T element)
{
if(len==MAXSIZE)
return -1;
data[len++]=element;
return 0;
}
//按下标删除
template <typename T>
int S<T>::delete_index(int index)
{
if(len==0)
return -1;
for(int i=index;i<len;i++)
{
data[i]=data[i+1];
}
len--;
return 0;
}
//按下表查找
template <typename T>
int S<T>::search_index(int index)
{
if(len==0)
return -1;
return data[index];
}
//按下表修改
template <typename T>
int S<T>::revise_index(int index,T element)
{
if(len==0)
return -1;
data[index]=element;
}
template <typename T>
void S<T>::show()
{
for(int i=0;i<len;i++)
{
cout<<data[i]<<endl;
}
}
int main()
{
S<int> s1;
s1.empty();
s1.insert_rear(20);
s1.show();
return 0;
}
?