解题思路:
注意事项:
参考代码:
#include<bits/stdc++.h> using namespace std; typedef struct Node{ int n; int g; struct Node *next; }node; node*creat(int n){//创建带头结点的链表 node*head,*p,*s; head=(node*)malloc(sizeof(node)); head->next=NULL; p=head; for(int i=1;i<=n;i++) { s=(node*)malloc(sizeof(node)); s->next=NULL; cin>>s->n>>s->g; p->next=s; p=s; } return head; } node*hebing(node *h1,node*h2){//合并两个链表 node*p; p=h1->next; while(p->next!=NULL) p=p->next; p->next=h2->next; return h1; } void ec(node*a,node*b){//交换两个节点的数据 int temp=a->g; a->g=b->g; b->g=temp; int t=a->n; a->n=b->n; b->n=t; } node*sort(node*h,int n){//利用冒泡排序 node*p,*s; for(int i=1;i<=n-1;i++){ p=h->next,s=p->next; while(s!=NULL){ if(p->n>s->n) ec(p,s); p=s,s=s->next; } } return h; } int main(){ int n,m; node*H,*q,*y; node*H1,*H2; cin>>n>>m; H1=creat(n); H2=creat(m); y=hebing(H1,H2); H=sort(y,m+n); q=H->next; while(q!=NULL) { cout<<q->n<<" "<<q->g<<endl; q=q->next; } }
0.0分
2 人评分
C语言训练-尼科彻斯定理 (C语言代码)。。。内含证明定理浏览:2065 |
C语言训练-求矩阵的两对角线上的元素之和 (C语言代码)浏览:700 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:682 |
简单的a+b (C语言代码)浏览:643 |
不会做的浏览:871 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:1242 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:403 |
拆分位数 (C语言代码)浏览:514 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:539 |
A+B for Input-Output Practice (II) (C语言代码)浏览:596 |