Light


私信TA

用户名:uq_66472224170

访问量:1540

签 名:

等  级
排  名 2449
经  验 2209
参赛次数 0
文章发表 6
年  龄 20
在职情况 学生
学  校 南通大学
专  业 计算机科学与技术

  自我简介:

TA的其他文章

解题思路:

注意事项:

参考代码:

#include<iostream>

using namespace std;

struct student

{

int id;

int score;

student *next;

};

student *create(int n)

{

student *head=NULL,*p1,*p2;

p1=new student;

head=p1;

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

{

cin>>p1->id>>p1->score;

p2=p1;

p1=new student;

p2->next=p1;

}

p1->next=NULL;

return head;

}

student *sort(student *head1,student *head2,int n,int m)

{

student *p[100];

student *t;

p[0]=head1;

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

{

p[i]=p[i-1]->next;

}

p[n]=head2;

for(int i=n+1;i<n+m;i++)

{

p[i]=p[i-1]->next;

}

for(int i=0;i<n+m-1;i++)

    for(int j=0;j<n+m-i-1;j++)

    {

    if(p[j]->id>p[j+1]->id)

    {

    t=p[j];

    p[j]=p[j+1];

    p[j+1]=t;

}

}

for(int i=n+m;i>0;i--)

{

p[i-1]->next=p[i];

}

    return p[0];

}

void print(student *head,int n)

{

student *p=head;

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

{

cout<<p->id<<" "<<p->score<<endl;

p=p->next;

}

}

int main()

    int n,m;

    cin>>n>>m;

    student *head1,*head2,*p;

    head1=create(n);

    head2=create(m);

head1=sort(head1,head2,n,m);

print(head1,n+m);

    return 0;

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区