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;
    } 
}


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

c本身就支持bool,true和false,为什么还要重新定义啊?而且重定义enum、true、false、bool这些都是c的关键字(参见C99标准),直接用bool就好了。

因为true,false,bool 已经是保留字了,再定义就冲突了,可以改成下面的:
typedef enum {False=0,True=1} Bool;

第64行: if(L->Data[i]==tmp) 这里的tmp 应该改成:x