#include<iostream>
using namespace std;
#define ERROR 0;
#define OVERFLOW -2;
#define OK 1;
#define MaxSize 100;
//线性表顺序存储结构c++实现
template<typename T>
class SqlList {
public:
SqlList() {};
SqlList(int Size) {
m_size = Size;
Elem = new T[Size];
m_length = 0;
}
T& operator [](int x)
{
if (x >= m_length)
{
throw - 1;
}
else
{
return Elem[x];
}
}
void Getm_length() {
return m_length;
}
void Getm_size() {
return m_size;
}
int InsertSqlList(int Position,T item) {
if (Position<1 || Position>m_length+1) {
return ERROR;
}
else if (m_length + 1 > m_size) {
return OVERFLOW;
}
else {
for (int i = m_length; i >= Position; i--) {
Elem[i]=Elem[i-1]
}
Elem[Position - 1] = item;
m_length++;
}
return OK;
}
int DeleteSqlList(int Position) {
if (Position<1 || Position>m_length - 1) {
return ERROR;
}
else {
for (int i = Position; i < m_length; i++) {
Elem[i - 1] = Elem[i];
}
m_length--;
}
}
int LocateSqlList(T e) {
for (int i = 0; i <= m_length - 1; i++) {
if (Elem[i] == e) {
return e;
break;
}
else return ERROR;
}
}
void DestorySqlList() {
delete Elem[];
m_length = 0;
m_size = 0;
}
~SqlList() {
delete[]Elem;
}
private:
T* Elem;
int m_length;
int m_size;
};
int main() {
SqlList<string> s(20);
s.InsertSqlList(1, "a");
cout << s[0] << endl;
system("pause");
return 0;
}