#include<stdio.h> #define MAXSIZE 100 //顺序表的结果定义 typedef struct{ int data[MAXSIZE]; int num; }SeqList; //建立顺序表 void CreateSeqList(SeqList *S){ S->num = 0; } //尾部插入元素 void Insert_Tail(SeqList *S,int e){ S->data[++S->num] = e; } //随机插入 void Insert_Random(SeqList *S,int n,int x){ int i; for(i=++S->num;i>n;i--){ S->data[i] = S->data[i-1]; } S->data[n] = x; } //删除元素 void DeleteSeqList(SeqList *S,int n){ int i; if(n<1||n>S->num){ return ; } for(i=n;i<S->num;i++){ S->data[i] = S->data[i+1]; } S->num--; } //打印顺序表 void DisplaySeqList(SeqList *S){ int i; for(i=1;i<=S->num;i++){ printf("%d ",S->data[i]); } printf("\n"); } int main(void){ SeqList S; int i; CreateSeqList(&S); for(i=1;i<=10;i++){ Insert_Tail(&S,i); } DisplaySeqList(&S); Insert_Random(&S,2,100); DisplaySeqList(&S); DeleteSeqList(&S,15); DisplaySeqList(&S); return 0; }