scorescore 2022-03-17 15:04 采纳率: 80%
浏览 34
已结题

用链表写排序,编译报错找不出原因

问题遇到的现象和发生背景

这是我写的链表插入排序,但是没法编译过去。我用的乌邦图

问题相关代码,请勿粘贴截图

#include <stdio.h>
#include <stdlib.h>
typedef int ElemType;
typedef struct Node
{
ElemType date;
struct Node next;
}node;
node
create_linkedlist(void)

{
int d;

node *p=NULL;
node *fist=NULL;
node *last=NULL;

while(1)
{
   scanf("%d",&d);
   if(d==0)
    {
        break;
    }
   p=(node *)malloc(sizeof(*p));
   p->date=d;
   p->next=NULL;
    if(fist==NULL)
   {

        fist=p;
        last=p;
   }
   else
   {
        last->next=p;
        last=p;
   }
   
}
return fist;

}*/

node *create_linkedlist_v2(void)
{
node *p=NULL;
node *h=NULL;
int d;
while(1)
{
p=malloc(sizeof(*p));
scanf("%d",&d);
if(d==0)
{
break;
}
else
{
p->date=d;
h=Insert(h,p);

    }
    return h;
    


}

}

void print_list(node *p)
{
while(p)
{
printf("%d",p->date);
// printf("%p\n" ,p->date);
p=p->next;

    //printf("%p\n",p);
}

}
node *Insert(node *h,node *ph)
{

node *pr=NULL;//找ps的前一个位置
node *ps=NULL;//找比p大的位置
if(ph==NULL)
{
    return h;
}   
if(h==NULL)
{
    return ph;
}
ps=h;

while(ps)
{
    if(ps->date>ph->date)
    {
       break;
    }

     pr=ps;
     ps=ps->next;


}
if(ps==NULL)
{
   pr->next=ph;
}
else
{
    if(ps==h)
    {
        ph->next=ps;
        h=ph;
    }
    else
    {
        pr->next=ph;
        ph->next=ps;
    }
}

return h;

}

int main()
{
node *h=create_linkedlist_v2();

//node *a=insert(h,p);
 print_list(h);

}

运行结果及报错内容

01链表.c: In function ‘create_linkedlist_v2’:
01链表.c:63:15: warning: implicit declaration of function ‘Insert’; did you mean ‘qsort’? [-Wimplicit-function-declaration]
h=Insert(h,p);

           qsort

01链表.c:63:14: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
h=Insert(h,p);
^
01链表.c: At top level:
01链表.c:84:7: error: conflicting types for ‘Insert’
node *Insert(node *h,node *ph)

01链表.c:63:15: note: previous implicit declaration of ‘Insert’ was here
h=Insert(h,p);
这个报错内容

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

2条回答 默认 最新

  • 快乐鹦鹉 2022-03-17 15:10
    关注

    insert函数要写到create函数之前,因为create函数调用了Insert函数
    编译器找不到这个Insert函数具体指哪个,就开始一顿瞎猜,然后警告

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

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月20日
  • 已采纳回答 3月17日
  • 创建了问题 3月17日

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化