#include <iostream>
#include<stdlib.h>
using namespace std;
#define max 100
typedef int element;
typedef struct sList {
element data[max];
int listLen;
}seqList;
void initialList(seqList* L) {
L->listLen = 0;
}
int listInsert(seqList* L,element x,int i) {
int j;
if (i<1 || i>L->listLen)
return 0;
else if (L->listLen == max)
return 0;
else{
for (j = L->listLen - 1; j > i - 1; j--)
L->data[j + 1] = L->data[j];
L->data[i - 1] = x;
return 1;
}
}
int listAdd(seqList* L ) {
if (L->listLen >= max)
return 0;
else {
cout << "请输入一组数据:";
for (int i = 0; ; i++) {
cin >> L->data[i];
L->listLen++;
}
return 1;
}
}
void listPrint(seqList* L) {
for (int i = 0; i < L->listLen; i++) {
cout << L->data[i];
}
}
int main() {
seqList* L = new seqList;
initialList(L);
int n,a[]={0},k,i;
cout << "请输入顺序表长度:";
cin >> n;
cout << endl;
listAdd(L);
cout << "输入要插入的数以及插入位置:";
cin >> k>>i;
listInsert(L, k,i);
listPrint(L);
}
我不知道我的listAdd函数,是否把数据写入顺序表中了,可以帮我看看吗?
然后,他运行到这里就不行了,不知道为什么