注册 登录
编程论坛 C语言论坛

为神马Compile Error,错误提示在后面

浮烟醉 发布于 2019-09-27 19:53, 1875 次点击
程序代码:
#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)'
1 回复
#2
浮烟醉2019-09-27 22:12
已经解决了,将position改成int就行
只有本站会员才能查看附件,请 登录

可是又有新问题,遍历输出后删除操作没有运行是为什么,而且输出一长串不明数字,求大神解答ing
1