#include <iostream>
#include <stdlib.h>
#pragma warning(disable:4996)
#define MaxSize 100
typedef int Elemtype;
typedef struct SqList
{
Elemtype data[MaxSize];
int length;
void init() {
this->length = 0;
}
bool append(Elemtype e)
{
if (this->length+1 > MaxSize)
return false;
else
{
this->data[length] = e;
this->length++;
return true;
}
}
bool add(int index, Elemtype e)
{
if (index > this->length || this->length+1 > MaxSize)
return false;
else
{
for (int i = length; i >= index-1; i--)
{
this->data[i] = this->data[i - 1];
}
this->data[index - 1] = e;
this->length++;
return true;
}
}
bool del(int index,Elemtype &e)
{
if (index > length)
return false;
else
{
e = this->data[index - 1];
for (int i = index; i < this->length; i++)
{
this->data[i - 1] = this->data[i];
}
this->length--;
}
return true;
}
}SqList;
typedef struct SeqList
{
Elemtype *data;
int length, Max;
void init() {
this->length = 0;
}
}SeqList;
SqList createSqList()
{
SqList L;
L.init();
int x;
scanf("%d", &x);
for (int i = 0; i < MaxSize; i++)
{
if (x != 999)
{
L.data[i] = x;
L.length++;
scanf("%d", &x);
}
else
return L;
}
return L;
}
//动态创建
SeqList createSeqList(int len)
{
SeqList SL;
SL.data = (Elemtype*)malloc(sizeof(Elemtype)*len);
SL.init();
SL.Max = len;
int x;
scanf("%d", &x);
for (int i = 0; i < len; i++)
{
if (x != 999)
{
SL.data[i] = x;
SL.length++;
scanf("%d", &x);
}
else
return SL;
}
return SL;
}
void PrintList(SqList L)
{
for (int i = 0; i < L.length; i++)
{
printf("%4d", L.data[i]);
}
printf("\n");
}
void PrintList(SeqList SL)
{
for (int i = 0; i < SL.length; i++)
{
printf("%4d", SL.data[i]);
}
printf("\n");
}
int main(int agrc, char **argv)
{
#if 0
SqList L;
L.init();
L.append(1);
L.append(2);
L.add(2, 3);
int x;
L.del(2, x);
PrintList(L);
printf("%4d\n", x);
#endif // 0
#if 0
SqList L = createSqList();
PrintList(L);
L.append(36);
PrintList(L);
L.add(2, 0);
PrintList(L);
int x;
L.del(3, x);
PrintList(L);
printf("%4d", x);
#endif // 0
SeqList SL = createSeqList(5);
PrintList(SL);
system("pause");
}