鱼C论坛

 找回密码
 立即注册
查看: 711|回复: 3

[已解决]看不懂的报错

[复制链接]
发表于 2020-3-20 16:31:20 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include<stdio.h>
  2. #include<malloc.h>
  3. #define OK 1
  4. #define ERROR 0
  5. #define LIST_INIT_SIZE 100
  6. #define LISTINCREMENT 10
  7. #define ElemType int

  8. typedef struct
  9. {
  10.         int *elem;
  11.         int length;
  12.         int listsize;
  13. }SqList;

  14. int InitList_Sq(SqList &L)
  15. {
  16.    L.elem=new ElemType(MAXSIZE);
  17.    if(!L.elem) exit(ERROR);
  18.    L.length=0;
  19.    return OK;
  20. }

  21. int Load_Sq(SqList &L)

  22.         int i;
  23.         if(L.length==0) printf("The List is empty!");  
  24.         {
  25.                 printf("The List is: ");
  26.                 for(i=0;i<L.length;i++) printf("%d ",L.elem);  
  27.         }
  28.         printf("\n");
  29.         return OK;
  30. }

  31. int ListInsert_Sq(SqList &L,int i,int e)
  32. {
  33.    int j;
  34.    if(i<1||i>L.length+1)
  35.    return ERROR;
  36.    if(L.length==MAXSIZE) return ERROR;
  37.    for(j=L.length-1;j>=i-1;j--)
  38.      L.elem[j+1]=L.elem[j];
  39.      L.elem[i-1]=e;
  40.      ++L.length;
  41.      return OK;
  42. }

  43. int ListDelete_Sq(SqList &L,int i, int &e)
  44. {
  45.     int j;
  46.    if(i<1||i>L.length+1)
  47.    return ERROR;
  48.     for(j=i-1;j<L.length;j++)
  49.     L.elem[j]=L.elem[j+1];
  50.     --L.length;
  51.     return OK;

  52. }

  53. int main()
  54. {
  55.         SqList T;
  56.         int a, i;
  57.         ElemType e, x;
  58.         if(T.elem)   
  59.         {
  60.                 printf("A Sequence List Has Created.\n");
  61.         }
  62.         while(1)
  63.         {
  64.                 printf("1:Insert element\n2:Delete element\n3:Load all elements\n0:Exit\nPlease choose:\n");
  65.                 scanf("%d",&a);
  66.                 switch(a)
  67.                 {
  68.                         case 1: scanf("%d%d",&i,&x);
  69.                                         if(i<1||i>T.length+1) printf("Insert Error!\n"); // 判断i值是否合法
  70.                                         else printf("The Element %d is Successfully Inserted!\n", x);
  71.                                         break;
  72.                         case 2: scanf("%d",&i);
  73.                                         if(i<1||i>T.length+1) printf("Delete Error!\n"); // 判断i值是否合法
  74.                                         else printf("The Element %d is Successfully Deleted!\n", e);
  75.                                         break;
  76.                         case 3: Load_Sq(T);
  77.                                         break;
  78.                         case 0: return 1;
  79.                 }
  80.         }
  81. }
复制代码
微信图片_20200320162911.png
最佳答案
2020-3-20 16:54:54
我改好的,没有错误和警告了
#include <stdio.h>
#include <malloc.h>
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define ElemType int

#include <stdlib.h>
#define MAXSIZE 50

typedef struct
{
        int *elem;
        int length;
        int listsize;
}SqList;


int InitList_Sq(SqList *L)
{
   L->elem = (int*)malloc(MAXSIZE);
   if(!L->elem) exit(ERROR);
   L->length=0;
   return OK;
}

int Load_Sq(SqList *L)
{
        int i;
        if(L->length==0)
                        printf("The List is empty!");
                else
        {
                printf("The List is: ");
                for(i=0;i<L->length;i++) printf("%d ",L->elem);  
        }
        printf("\n");
        return OK;
}

int ListInsert_Sq(SqList *L,int i,int e)
{
   int j;
   if(i<1||i>L->length+1)
   return ERROR;
   if(L->length==MAXSIZE) return ERROR;
   for(j=L->length-1;j>=i-1;j--)
     L->elem[j+1]=L->elem[j];
     L->elem[i-1]=e;
     ++L->length;
     return OK;
}

int ListDelete_Sq(SqList *L,int i, int *e)
{
    int j;
   if(i<1||i>L->length+1)
   return ERROR;
    for(j=i-1;j<L->length;j++)
    L->elem[j]=L->elem[j+1];
    --L->length;
    return OK;

}

int main()
{
        SqList T;
        int a, i;
        ElemType e, x;
        if(T.elem)   
        {
                printf("A Sequence List Has Created.\n");
        }
        while(1)
        {
                printf("1:Insert element\n2:Delete element\n3:Load all elements\n0:Exit\nPlease choose:\n");
                scanf("%d",&a);
                switch(a)
                {
                        case 1: scanf("%d%d",&i,&x);
                                        if(i<1||i>T.length+1) printf("Insert Error!\n"); // 判断i值是否合法
                                        else printf("The Element %d is Successfully Inserted!\n", x);
                                        break;
                        case 2: scanf("%d",&i);
                                        if(i<1||i>T.length+1) printf("Delete Error!\n"); // 判断i值是否合法
                                        else printf("The Element %d is Successfully Deleted!\n", e);
                                        break;
                        case 3: Load_Sq(&T);
                                        break;
                        case 0: return 1;
                }
        }
}
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-3-20 16:35:35 | 显示全部楼层
这是C语言还是C++ ?
C语言中有引用?我怎么不知道?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-20 16:54:54 | 显示全部楼层    本楼为最佳答案   
我改好的,没有错误和警告了
#include <stdio.h>
#include <malloc.h>
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define ElemType int

#include <stdlib.h>
#define MAXSIZE 50

typedef struct
{
        int *elem;
        int length;
        int listsize;
}SqList;


int InitList_Sq(SqList *L)
{
   L->elem = (int*)malloc(MAXSIZE);
   if(!L->elem) exit(ERROR);
   L->length=0;
   return OK;
}

int Load_Sq(SqList *L)
{
        int i;
        if(L->length==0)
                        printf("The List is empty!");
                else
        {
                printf("The List is: ");
                for(i=0;i<L->length;i++) printf("%d ",L->elem);  
        }
        printf("\n");
        return OK;
}

int ListInsert_Sq(SqList *L,int i,int e)
{
   int j;
   if(i<1||i>L->length+1)
   return ERROR;
   if(L->length==MAXSIZE) return ERROR;
   for(j=L->length-1;j>=i-1;j--)
     L->elem[j+1]=L->elem[j];
     L->elem[i-1]=e;
     ++L->length;
     return OK;
}

int ListDelete_Sq(SqList *L,int i, int *e)
{
    int j;
   if(i<1||i>L->length+1)
   return ERROR;
    for(j=i-1;j<L->length;j++)
    L->elem[j]=L->elem[j+1];
    --L->length;
    return OK;

}

int main()
{
        SqList T;
        int a, i;
        ElemType e, x;
        if(T.elem)   
        {
                printf("A Sequence List Has Created.\n");
        }
        while(1)
        {
                printf("1:Insert element\n2:Delete element\n3:Load all elements\n0:Exit\nPlease choose:\n");
                scanf("%d",&a);
                switch(a)
                {
                        case 1: scanf("%d%d",&i,&x);
                                        if(i<1||i>T.length+1) printf("Insert Error!\n"); // 判断i值是否合法
                                        else printf("The Element %d is Successfully Inserted!\n", x);
                                        break;
                        case 2: scanf("%d",&i);
                                        if(i<1||i>T.length+1) printf("Delete Error!\n"); // 判断i值是否合法
                                        else printf("The Element %d is Successfully Deleted!\n", e);
                                        break;
                        case 3: Load_Sq(&T);
                                        break;
                        case 0: return 1;
                }
        }
}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-20 17:06:48 | 显示全部楼层
新手 就直接把题目抄下来了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-13 17:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表