初冀 2023-03-16 00:08 采纳率: 61%
浏览 13
已结题

这里为什么不能进行下一步操作


#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);

}

img


我不知道我的listAdd函数,是否把数据写入顺序表中了,可以帮我看看吗?
然后,他运行到这里就不行了,不知道为什么

  • 写回答

3条回答 默认 最新

  • 快乐鹦鹉 2023-03-16 04:30
    关注

    for都没有结束条件,死循环了。
    代码很乱,都不知道为啥要写函数吧

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月30日
  • 创建了问题 3月16日

悬赏问题

  • ¥50 AI大模型精调(百度千帆、飞浆)
  • ¥15 关于#c语言#的问题:我在vscode和codeblocks中编写c语言时出现打不开源文件该怎么办
  • ¥15 非科班怎么跑代码?如何导数据和调参
  • ¥15 福州市的全人群死因监测点死亡原因报表
  • ¥15 Altair EDEM中生成一个颗粒,并且各个方向没有初始速度
  • ¥15 系统2008r2 装机配置推荐一下
  • ¥500 服务器搭建cisco AnyConnect vpn
  • ¥15 悬赏Python-playwright部署在centos7上
  • ¥15 psoc creator软件有没有人能远程安装啊
  • ¥15 快速扫描算法求解Eikonal方程咨询