![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5CMlRDMkhTN1QzY3gDN5IzNycjY2QGZyQmNwEzNihTOw8CX0JXZ252bj91Ztl2Lc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
2009-01-05
C语言问题从键盘输入8个数,用选择法按由大到小的循序排列并输出,要求用指针来实现。
你应该自己实现这个小程序。
例子,单向链表排序(冒泡):
struct student
{
int num;
struct student *next;
}
struct student *paixu(struct student *head)
{
struct student *p,*q;
int temp;
q=head;
while(q->next!=null)
{
p=head;
while(p->next!=null) //这个判断有冗余,待改进
{
if (p->num > p->next->n...全部
你应该自己实现这个小程序。
例子,单向链表排序(冒泡):
struct student
{
int num;
struct student *next;
}
struct student *paixu(struct student *head)
{
struct student *p,*q;
int temp;
q=head;
while(q->next!=null)
{
p=head;
while(p->next!=null) //这个判断有冗余,待改进
{
if (p->num > p->next->num) //交换数值
{
temp=p->num;
p->num=p->next->num;
p->next->num=temp;
}
p=p->next;
}
q=q->next;
}
return *head;
}
2 void arrange(NODE *head)
{
NODE *p1,*p2,*p3;
p1=head->next;
p2=NULL;
p3=head;
while(p2!=head->next->next)
{
while(p1->next!=p2)
{
if (p1->countnext->count)
{ p3->next=p1->next;
p1->next=p1->next->next;
p3->next->next=p1;
}
p3=p1;
p1=p1->next;
}
p2=p1;
p1=head->next;
p3=head;
}
。收起