求解一个C语言单链表的题

来源:百度知道 编辑:UC知道 时间:2024/07/13 21:36:51
题1:已知带头结点的动态单链表L中的结点是按整数数值递增排列的,试写一算法将值为X的结点插入表L中,使L仍然有序。
题2:设计一算法,逆置带头结点的动态单链表L。
这科没怎么学明白,有点不会,嘿嘿~!大家帮帮忙,写得详细点最好~!!

void ins(struct point *L,int i)
{
struct point *t=L,*p=malloc(sizeof(struct point));
p->data=i;
while (L!=NULL)
{
t=L;
if (i>L->data) L=L->next;
else {
p->next=L->next;
L->next=p;
break;
}
}
if (L==NULL) {
p->next=NULL;
t->next=p;
}
}

struct student *insert(struct student *head) //插入信息
{
struct student *p1,*p2,*stu;
stu=(struct student *)malloc(sizeof(struct student));
scanf("%d%s%s%s%f",&stu->num,stu->name,stu->place,stu->college,&stu->score);
p1=head;
while((stu->num>p1->num) && (p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
while(p1->num==stu->num)
{
printf("学号重复,重新输入!!!!!\n");