lemonjgg 2021-09-11 21:28 采纳率: 33.3%
浏览 111
已结题

C语言bool型定义报错,怎么解决?

枚举类型报错,编译器是DEVC++。文件保存是.cpp。后面是所有代码,写的顺序表操作。

img

#include <stdio.h>
#include <stdlib.h>

#define MAXSIZE 5
#define ERROR -1
typedef enum {false, true} bool;
typedef int ElementType;
typedef int Position;
typedef struct LNode *List;
struct LNode {
    ElementType Data[MAXSIZE];
    Position Last; /* 保存线性表中最后一个元素的位置 */
};

List MakeEmpty(); 
Position Find( List L, ElementType X );
bool Insert( List L, ElementType X, Position P );
bool Delete( List L, Position P );


int main()
{
    List L;
    ElementType X;
    Position P;
    int N;

    L = MakeEmpty();
    scanf("%d", &N);
    while ( N-- ) {
        scanf("%d", &X);
        if ( Insert(L, X, 0)==false )
            printf(" Insertion Error: %d is not in.\n", X);
    }
    scanf("%d", &N);
    while ( N-- ) {
        scanf("%d", &X);
        P = Find(L, X);
        if ( P == ERROR )
            printf("Finding Error: %d is not in.\n", X);
        else
            printf("%d is at position %d.\n", X, P);
    }
    scanf("%d", &N);
    while ( N-- ) {
        scanf("%d", &P);
        if ( Delete(L, P)==false )
            printf(" Deletion Error.\n");
        if ( Insert(L, 0, P)==false )
            printf(" Insertion Error: 0 is not in.\n");
    }
    return 0;
}

/* 你的代码将被嵌在这里 */
List MakeEmpty()
{ //L->Last是int 不能用NULL 
    List L=(List)malloc(sizeof(struct LNode)) ;
    L->Last=0;
}
Position Find( List L, ElementType X ){
    
        for(int i=0;i<=L->Last;i++){
        if(L->Data[i]==tmp)
             return i;
    }
    return ERROR;
    
    }
bool Insert( List L, ElementType X, Position P ){
    //插入就是数组后移 结点没有指针 
    if(L->Last==MAXSIZE){
        return FULL;
    }
    else if(P<0||P>L->Last){
        printf("ILLEGAL POSITION\n");
        return false;
    }    
    else if{
            for(int j=L->Last;j>=P;j--)
                   L->Data[j+1]=L->Data[j];    
     
     L->Data[P]=X;
     //最后一个元素位置+1  
     L->Last++; 
     return true;
    }      
}
bool Delete( List L, Position P ){
    //删除元素 数组后移
    if(P<0||P>L->Last){
        printf("ILLEGAL POSITION\n");
        return false;
    }else{
        for(int k=p;k<=L->Last;k++)
          L->Data[P]=L->Data[P+1];
    --L->Last;    
    return true;
    } 
}


  • 写回答

3条回答 默认 最新

  • qfl_sdu 2021-09-11 21:35
    关注

    c语言中没有bool类型,用int类型代替

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 9月21日
  • 已采纳回答 9月13日
  • 创建了问题 9月11日

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置