主题:求救高手,紧急!!!
#include <stdio.h>
#include <stdlib.h>
typedef struct polynode
{ char name[6];
int num;
int score;
struct polynode *next;
} PNode;
PNode *Creat_Linklist(int n);
PNode *sort_num(PNode *head);
void print_Linklist(PNode *head);
int main()
{
PNode *p;
int n;
printf("请输入学生的人数:\n");
scanf("%d",&n);
p=Creat_Linklist(n);
p=sort_num(p);
print_Linklist(p);
return 0;
}
PNode *Creat_Linklist(int n)
{
PNode *head,*p,*q;
int i;
head=(PNode *)malloc(sizeof(PNode));
head->next=NULL;
p=head;
printf("请输入学生的信息:\n");
for(i=1;i<=n;i++)
{q=(PNode *)malloc(sizeof(PNode));
printf("姓名:");
scanf("%s",&q->name);
printf("学号:");
scanf("%d",&q->num);
printf("成绩:");
scanf("%d",&q->score);
q->next=NULL;
p->next=q;
p=q;
}
return(head);
}
void print_Linklist(PNode *head)
{ PNode *p;
p=head->next;
printf("姓名 学号 成绩\n ");
while(p)
{printf("%-5s%5d%5d\n",p->name,p->num,p->score);
p=p->next;
}
}
PNode *sort_num(PNode *head)
{ PNode *p,*pre,*pt,*head1;
int inum;
p=head->next;
head1=(PNode *)malloc(sizeof(PNode));
head1->next=NULL;
pt=head1;
while(p)
{inum=p->num;
if(p->next=NULL) {pt->next=p; p->next=NULL;}
else
{if(inum<p->next->num) {inum=p->next->num;pre=p;}
p=p->next;
}
if(pre->next=NULL) {pt->next=pre;pt=pre;pt->next=NULL;}
else if(pre->next->next=NULL){p=pre->next;pre->next=NULL;pt->next=p;pt=p;pt->next=NULL;}
p=pre->next;
pre->next=p->next;
pt->next=p;
pt=p;
p->next=NULL;
p=head->next;
}
pt->next=p;
pt=p;
pt->next=NULL;
return(head1);
}
运行没错误,但没结果,该怎么改?
PNode *sort_num(PNode *head)函数 有点问题
#include <stdlib.h>
typedef struct polynode
{ char name[6];
int num;
int score;
struct polynode *next;
} PNode;
PNode *Creat_Linklist(int n);
PNode *sort_num(PNode *head);
void print_Linklist(PNode *head);
int main()
{
PNode *p;
int n;
printf("请输入学生的人数:\n");
scanf("%d",&n);
p=Creat_Linklist(n);
p=sort_num(p);
print_Linklist(p);
return 0;
}
PNode *Creat_Linklist(int n)
{
PNode *head,*p,*q;
int i;
head=(PNode *)malloc(sizeof(PNode));
head->next=NULL;
p=head;
printf("请输入学生的信息:\n");
for(i=1;i<=n;i++)
{q=(PNode *)malloc(sizeof(PNode));
printf("姓名:");
scanf("%s",&q->name);
printf("学号:");
scanf("%d",&q->num);
printf("成绩:");
scanf("%d",&q->score);
q->next=NULL;
p->next=q;
p=q;
}
return(head);
}
void print_Linklist(PNode *head)
{ PNode *p;
p=head->next;
printf("姓名 学号 成绩\n ");
while(p)
{printf("%-5s%5d%5d\n",p->name,p->num,p->score);
p=p->next;
}
}
PNode *sort_num(PNode *head)
{ PNode *p,*pre,*pt,*head1;
int inum;
p=head->next;
head1=(PNode *)malloc(sizeof(PNode));
head1->next=NULL;
pt=head1;
while(p)
{inum=p->num;
if(p->next=NULL) {pt->next=p; p->next=NULL;}
else
{if(inum<p->next->num) {inum=p->next->num;pre=p;}
p=p->next;
}
if(pre->next=NULL) {pt->next=pre;pt=pre;pt->next=NULL;}
else if(pre->next->next=NULL){p=pre->next;pre->next=NULL;pt->next=p;pt=p;pt->next=NULL;}
p=pre->next;
pre->next=p->next;
pt->next=p;
pt=p;
p->next=NULL;
p=head->next;
}
pt->next=p;
pt=p;
pt->next=NULL;
return(head1);
}
运行没错误,但没结果,该怎么改?
PNode *sort_num(PNode *head)函数 有点问题