活不明白


私信TA

用户名:hbmb

访问量:15789

签 名:

等  级
排  名 1126
经  验 3105
参赛次数 0
文章发表 38
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include<stdio.h>

#include<stdlib.h>

#include<string.h>



typedef struct Stu1{

int  num;

int  score;

struct Stu1 *next;

}stu1;


stu1 *initLink(int n)

{

stu1 *p=(stu1*)malloc(sizeof(stu1));

stu1 *temp=p;

for(int i=0;i<n;i++)

{

stu1 *a=(stu1*)malloc(sizeof(stu1));

scanf("%d%d",&a->num,&a->score);

a->next=NULL;

temp->next=a;

temp=temp->next;

}

return p;

}


stu1 *hebing(stu1 *A,stu1 *B)

{

stu1 *temp1=A;

while(temp1->next!=NULL)

{

temp1=temp1->next;

}

stu1 *temp2=B;

temp1->next=temp2->next;

free(temp2);

return A;

}


int disply(stu1 *A)

{

stu1 *temp=A;

while(temp->next!=NULL)

{

   temp=temp->next;

printf("%d %d\n",temp->num,temp->score);

}

return 0;

}


int sort(stu1 *C)

{

stu1 *temp1=NULL;

stu1 *temp2=NULL;

stu1  tmp;

stu1  tmp2;

for(temp1=C->next;temp1->next!=NULL;temp1=temp1->next)

{

for(temp2=temp1->next;temp2!=NULL;temp2=temp2->next)

{

if(temp1->num > temp2->num)

{

tmp=*temp1;

*temp1=*temp2;

*temp2=tmp;

tmp2.next=temp1->next;

temp1->next=temp2->next;

temp2->next=tmp2.next;}

}

}

return 0;

}


int destory(stu1 *C)

{

stu1 *temp=C;

stu1 *tmp;

while(temp!=NULL)

{

tmp=temp->next;

free(temp);

}

return 0;

}


int main()

{

int n,m;

scanf("%d%d",&n,&m);

stu1 *A;

stu1 *B;

stu1 *C;

A=initLink(n);

B=initLink(m);

C=hebing(A,B);

sort(C);

disply(C);

destory(C);



    return 0;

}


 

0.0分

0 人评分

  评论区