使用devC++运行数据结构中动态数组的增删改查时出现错误
#include<stdlib.h>
#include<stdio.h>
#define InitSize 3
//1. 创造顺序表
typedef struct{
intdata;
int length;
int MaxSize;
}SeqList;
//2.初始化
void InInsert(SeqList&L){
L.data=(int)malloc(sizeof(int)*InitSize);
L.data=0;
L.length=InitSize;
}
//3.增加
bool InIertList(SeqList&L,int i,int e){
if(i<1||i>L.length+1){
return false;
}
for(int j=L.length;j>=i;j--){
L.data[j]=L.data[j-1];
}
L.data[i-1]=e;
L.length++;
return true;
}
//4.删除
bool ListDelect(SeqList&L,int i,int &e){
if(i<1||i>L.length){
return false;
}
e=L.data[i-1];
for(int j=i;j<L.length;i++){
L.data[j]=L.data[j+1];
}
L.length--;
return true;
}
//5.按值查找
int LocatList(SeqList&L,int e){
for(int i=0;i<L.length;i++){
if(L.data[i]==e){
return i+1;
printf("位置为:%d",i);
}
}
return 0;
}
int main(){
SeqList L;
InInsert(L);
InIertList(L,1,1);
InIertList(L,2,2);
InIertList(L,3,3);
InIertList(L,4,4);
InIertList(L,5,5);
for(int i=0;i<L.length;i++){
printf("[%d],%d\n",i,L.data[i]);
}
int e=-1;
ListDelect(L,2,e);
for(int i=0;i<L.length;i++){
printf("[%d],%d\n",i,L.data[i]);
}
LocatList(L,3);
return 0;
}
编译没问题,运行没结果,调试进入InIertList函数中for循环的时候报错
推荐观看他的博客
https://blog.csdn.net/weixin_64336132/article/details/123614404