又是单链表的排序问题,看看我错那儿了!
下面是一个建表加排序的函数,main里用createstacklinknode(&head)调用,head是头节点,已经指向NULL了。调用是,能正常输出链表,但是在冒泡排序那里就死了!
void createstacklinknode(struct linknode **headp)
{
int numbers;
register int tmp,tcurrent;
struct linknode *p,*order;
printf("\nInput Number:");
scanf("%ld",&numbers);
while(numbers)
{
p=(struct linknode *)malloc(sizeof(struct linknode));
p->data=numbers;
p->next=(*headp)->next;
(*headp)->next=p;
scanf("%ld",&numbers);
}
printf("\nThe create stack linknode is following:\n");
printf("------------------------------------------------\n");
p=(*headp)->next;
while (p!=NULL)
{
printf("%2ld *",p->data);
printf(" -> ");
p=p->next;
}
printf("NULL\n");
p=(*headp)->next;
tcurrent=p->data;
for(;p!=NULL;p=p->next)
{
for(;p!=NULL;p=p->next)
{
if(tcurrent<p->data)
{ tmp=tcurrent ;
tcurrent=p->data;
p->data=tmp;
}
}
p=(*headp)->next;
}
p=(*headp)->next;
while (p!=NULL)
{
printf("%2ld *",p->data);
printf(" -> ");
p=p->next;
}
printf("NULL\n");
}
另外我想把排序单独写成一个函数,参数怎么传递啊?我写的是这这样
申明:struct linknode *orderbyincrease(struct linknode **) //指向头节点指针的指针
调用:orderbyincrease( (*headp)->next );总是提示类型不匹配!
分不够再加啊!