为神马Compile Error,错误提示在后面
程序代码:
#include<stdbool.h> #include<stdio.h> #include<stdlib.h> typedef int ElementType; typedef struct LNode *PtrToLNode; struct LNode { ElementType Data; PtrToLNode Next; }; typedef PtrToLNode Position; typedef PtrToLNode List; List MakeEmpty() { List L; L = (List)malloc(sizeof(struct LNode)); L->Next = NULL; return L; } int Length(List L) { Position p; int cnt=0; p=L->Next; while(p!=NULL) { p=p->Next; cnt++; } return cnt; } /* 带头结点的插入 */ bool Insert( List L, ElementType X, int i ) { /* 这里默认L有头结点 */ Position tmp, pre; int cnt=0; pre=L; while(pre && cnt<i-1) { pre=pre->Next; cnt++; } if ( pre==NULL ||cnt!=i-1) { return false; } else { tmp = (Position)malloc(sizeof(struct LNode)); /* 申请、填装结点 */ tmp->Data = X; tmp->Next = pre->Next; pre->Next = tmp; return true; } } /* 带头结点的删除 */ bool Delete( List L, int i ) { /* 这里默认L有头结点 */ Position tmp, pre; int cnt=0; pre=L; while(pre && cnt<=i-1) { pre=pre->Next; cnt++; } if ( pre==NULL || cnt!=i-1||pre->Next==NULL) { return false; } else { tmp=pre->Next; pre->Next = tmp->Next; free(tmp); return true; } } int main(int argc,char** argv){ List L=MakeEmpty(); int n,op; Position i; ElementType x; scanf("%d",&n); while(n--) { scanf("%d",&op); switch(op) { case 1:scanf("%d %d",&x,&i); Insert(L,x,i); break; case 2:scanf("%d",&i); Delete(L,i); break; } } while(L!=NULL){ printf("%d",L->Data); L=L->Next; if(L!=NULL) printf(","); } return 0; }
In function 'int main(int, char**)'
[Error] invalid conversion from 'Position {aka LNode*}' to 'int' [-fpermissive]
[Note] initializing argument 3 of 'bool Insert(List, ElementType, int)'
[Error] invalid conversion from 'Position {aka LNode*}' to 'int' [-fpermissive]
[Note] initializing argument 2 of 'bool Delete(List, int)'