标题:单链表问题
取消只看楼主
FORTHGOER
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2020-7-6
结帖率:0
 问题点数:0 回复次数:1 
单链表问题
程序代码:
//define struct type
typedef struct Lnode {

    int data;
    struct LNode* next;
    
}Lnode;

//creat Link list
void CreatList() {

    //creat Head pointer and Tail pointer
    Lnode** Head;
    Lnode* Tail;

    //creat an empyt Link list
    *Head = (Lnode* )malloc(sizeof(Lnode));
    (*Head)->next = NULL;
    
    Tail = *Head;

    //insert data 
    for (int i = 0; i < 3; ++i) {
        
        //creat new node
        Lnode* P = (Lnode* )malloc(sizeof(Lnode));
        
        //update date domain and pointer domain of new node
        P->data = i;
        P->next = NULL;

        //update pointer domain of before node
        Tail->next = P;

        //update Tail pointer Location
        Tail = P;

    }

}  




gcc 9.2.0 报错
.\Link.c: In function 'CreatList':
.\Link.c:45:20: warning: assignment to 'struct LNode *' from incompatible pointer type 'Lnode *' {aka 'struct Lnode *'} [-Wincompatible-pointer-types]
   45 |         Tail->next = P;
      |                    ^


我觉得没错啊 Tail->next 与 P 都是 Lnode* 类型啊
搜索更多相关主题的帖子: pointer Head Link struct next 
2021-03-11 15:00
FORTHGOER
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2020-7-6
得分:0 
回复 楼主 FORTHGOER
line5: struct LNode* next -> struct Lnode* next
2021-03-11 16:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-505083-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014036 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved