问题遇到的现象和发生背景
这是我写的链表插入排序,但是没法编译过去。我用的乌邦图
问题相关代码,请勿粘贴截图
#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);
这个报错内容