m0_55782465 2021-11-07 07:51 采纳率: 0%
浏览 19

c++顺序存储结构malloc使用失败怎么办?

#include
#include<malloc.h>
using namespace std;
#define MaxSize 20
#define elemtype int
typedef struct
{
elemtype date[MaxSize];
int length;
}SqList;
int main() {
int a[MaxSize];
for (int i = 0; i < 9; i++) {
cin >> a[i];
}
SqListL= (SqList)malloc(sizeof(SqList));
void chushi1(SqList*);
chushi1(L);
void chushi2(SqList*, int a[], int);
chushi2(L, a, 15);
bool ListInsert(SqList*, int, int);
bool ListDelete(SqList*, int,int);
ListInsert(L, 6, 26);
int e = 0;
ListDelete(L, 7,e);
void shuchu(SqList*);
shuchu(L);
}
void chushi1(SqList*& L) {
L->length = 0;
}
void chushi2(SqList * &L, int a[], int n) {
int i = 0, k = 0;
while (i < n)
{
L->date[k] = a[i];
k++, i++;
}
L->length = k;
}
bool ListInsert(SqList*& L, int i,int e) {
int j;
if (i<1 || i>L->length + 1 || L->length == MaxSize) {
return false;
i--;
for (j = L->length; j > i; j--)
L->date[j] = L->date[ j- 1];
L->date[i] = e;
L->length++;
return true;
}
}
bool ListDelete(SqList*& L, int i,int&e) {
int j;
if (i<1 || i>L->length)
return false;
i--;
e = L->date[i];
for (j = i; j < L->length - 1; j++)
L->date[j] = L->date[j + 1];
L->length--;
return true;
}
void shuchu(SqList* L) {
for (int i = 0; i < L->length; i++)cout << L->date[i];
cout << endl;
}
哪位大佬帮我看一下/新手/c++线性表的顺序存储结构/没报错但就是运行失败

  • 写回答

3条回答 默认 最新

  • CSDN专家-link 2021-11-07 08:01
    关注

    insert函数中return false 位置不对啊

    评论

报告相同问题?

问题事件

  • 创建了问题 11月7日