#ifndef _SQLIST_H_
#define _SQLIST_H_
#include
#include
using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -1
#define MAXSIZE 100
typedef int Status;
typedef int KeyType;
typedef struct
{
KeyType key;
}Data;
typedef struct
{
Data *r; //结点数据
int lenth; //顺序表长度
int listsize; //最大长度
}SqList;
Status initSqList(SqList &L)
{
L.r = (Data *)malloc((MAXSIZE + 1) * sizeof(Data)); //含哨兵
if (!L.r)
exit (OVERFLOW);
L.lenth = 0;
L.listsize = MAXSIZE + 1;
return OK;
}
Status CreateSqList(SqList &L)
{
fstream file;
file.open("data.txt",ios::in);
if (!file)
{
cout<> L.r[i].key;
i++;
L.lenth++;
}
}
void Visit(SqList L)
{
cout << "遍历:";
for (int i = 1; i <= L.lenth; i++)
cout << L.r[i].key << " ";
cout << endl;
}
Status InsertElem(SqList &L, int n, Data e)
{
if (n L.lenth)
{
cout << "插入位置不合法" < L.listsize)
{
cout << "空间不足" <= n; i--)
L.r[i + 1] = L.r[i];
L.r[n] = e;
return OK;
}
Status deleteElem(SqList &L,KeyType e)
{
for (int i = 1; i <= L.lenth; i++)
{
if (L.r[i].key == e)
{
for(int j = i; j < L.lenth; j++)
L.r[j] = L.r[j + 1];
--L.lenth;
return OK;
}
}
cout << "不存在该元素" << endl;
return ERROR;
}
Status updateElem(SqList &L,KeyType e,Data d)
{
for (int i = 1; i <= L.lenth; i++)
{
if (L.r[i].key == e)
{
L.r[i] = d;
return OK;
}
}
cout << "不存在该元素" << endl;
return ERROR;
}
void Unique(SqList &L)
{
for (int i = 1; i < L.lenth; i++)
{
for(int j = i + 1; j <= L.lenth; )
{
if(L.r[i].key == L.r[j].key)
{
for (int k = j; k < L.lenth; k++)
L.r[k] = L.r[k + 1];
L.lenth--;
}
else
j++;
}
}
}
#endif