#include<stdio.h> #define SIZE 100//最大字节 enum BOOL {ERROR,OK}; typedef struct { char data[SIZE]; int last; }sqlist; void initial(sqlist &); //初始化线性表 BOOL insert(sqlist &, int, char); //在线性表中插入元素 BOOL del(sqlist&, int, char &); //在线性表中删除元素 int locate(sqlist, char); //在线性表中定位元素 void show(sqlist); void main() { int loc,flag,k; char ch; sqlist s; while (1) { scanf("%d",&k); switch (k) {case 1: initial(s); show(s); break; case 2: scanf("%d %c", &loc, &ch); insert(s, loc, ch); show(s); break; case 3: scanf("%d", &loc); del(s, loc, ch); show(s); printf("%c", ch); getchar(); break; case 4: scanf("%c", &ch); flag = locate(s, ch); printf("%d", flag); break; } } } BOOL insert(sqlist &s, int loc, char c) { int i; if (loc<1 && loc>s.last + 1) { printf("error"); return ERROR; } else if (s.last > SIZE)//线性表已满 { printf("s.last is out MAX"); return ERROR; } else{ for (i = s.last-1; i>=loc-1; i--) { s.data[i + 1] = s.data[i]; } s.data[loc-1] = c; s.last++; return OK; } } int locate(sqlist s, char ch) { char c; c = ch; int i; for (i = 0; i < s.last; i++) { if (s.data[i] == c)return i + 1; } if (i > s.last)return ERROR; } BOOL del(sqlist &s,int loc ,char &ch) { if (loc > s.last + 1 && loc < 1)return ERROR; ch = s.data[loc - 1]; int i; for (i = loc - 1; i <= s.last - 1; i++)s.data[i] = s.data[i + 1];//向左移动 s.data[i] = '