#define _CRT_SECURE_NO_WARNINGS 1#include #include #include #include #define MAXSIZE 1000typedef int DateType;typedef struct SeqList{ DateType arr[MAXSIZE]; size_t size;}SeqList;//打印静态顺序表void PrintSeqList(SeqList *Seq){ assert(Seq); if (Seq->size == 0) { printf("静态顺序表当前为空!\n"); return; } for (int index = 0; index < Seq->size; index++) { printf("%d-> ", Seq->arr[index]); }}//初始化void init(SeqList *Seq){ assert(Seq); memset(Seq->arr, 0, sizeof(DateType)* MAXSIZE); Seq->size = 0;}//尾插void PushBack(SeqList *Seq,DateType x){ if (Seq->size >= MAXSIZE) { printf("静态顺序表当前已满,无法插入!\n"); return; } Seq->arr[Seq->size++] = x;}//插入//void Insert(SeqList *Seq, size_t pos, DateType x)//{// assert(Seq);// assert(pos < Seq->size);//// if (Seq->size >= MAXSIZE)// {// printf("静态顺序表当前已满,无法插入!\n");// return;// }//// /*Seq->size++;*/// for (int index = Seq->size; index > pos;index--)// {// Seq->arr[index] = Seq->arr[index - 1];// }// Seq->arr[pos] = x;// Seq->size++;//}//查找int Find(SeqList *Seq,DateType x){ assert(Seq); int index = 0; while (index < Seq->size) { if (x == Seq->arr[index]) return index; index++; } return -1;}void Test2(SeqList *Seq){ init(Seq); PushBack(Seq, 0); PushBack(Seq, 1); PushBack(Seq, 2); PushBack(Seq, 3); PushBack(Seq, 4); PushBack(Seq, 5); PrintSeqList(Seq); printf("\n"); /*Insert(Seq, 2, 20); PrintSeqList(Seq); printf("\n");*/ int ret = Find(Seq, 10); printf("%d\n", ret);}int main(){ /*SeqList Seq; Test1(&Seq);*/ SeqList Seq; Seq.size = 0; Test2(&Seq); system("pause"); return 0;}