关于C语言链表排序的问题#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
struct number
{int num;
struct number *next;
};
int n;
struct number *creat()
{struct number *head;
struct number *p1,*p2;
n=0;
p1=p2=(struct number*)malloc(sizeof(struct number));
scanf("%d",&p1->num);
head=NULL;
while(p1->num!=0)
{n=n+1;
if(n==1) head=p1;
else p2->next=p1;;
p2=p1;
p1=(struct number*)malloc(sizeof(struct number));
scanf("%d",&p1->num);
}
p2->next=NULL;
return (head);
}
void print(struct number *head)
{struct number *p1,*p2,*p;
int i,j,t;
printf("这%d个数从小到大的排序为:\n",n);
if(head!=NULL)
for(j=0;j<n-1;j++)
{
p1=head;
p2=head;
for(i=0;i<n-1-j;i++)
{p2=p1->next;
if(p1->num>=p2->num)
{t=p1->num;
p1->num=p2->num;
p2->num=t;
}
p1=p1->next;
}
}
p=head;
if(head!=NULL)
do
{printf("%3d",p->num);
p=p->next;
}while(p!=NULL);
}
void main()
{struct number *head;
head=creat();
print(head);
}
请问各位大神本程序的原理,求把一些注意事项备注一下,比如那行是实现什么功能的,谢谢🙏