#include<bits/stdc++.h> using namespace std; struct node{//定义链表结点,头结点 xuehao 变量保存链表结点数 int xuehao,score; struct node *Next; }; typedef struct node Node; void tailinsert(int xuehao,int score,Node *L){//尾插法插入结点 Node *node = (Node*)malloc(sizeof(Node)); node->xuehao = xuehao; node->score = score; node->Next = NULL; if(L->xuehao==0){ L->Next = node; L->xuehao++; } else{ Node *temp = L->Next; while(temp->Next!=NULL){ temp = temp->Next; } temp->Next = node; L->xuehao++; } } void printlist(Node *L){ cout << L->xuehao << endl; Node *temp = L->Next; if(temp==NULL){ printf("Link list is empty\n"); return; } while(temp!=NULL){ printf("%d %d\n",temp->xuehao,temp->score); temp = temp->Next; } } void deletenode(Node *L1,Node *L2){//删除实现函数 Node *temp1 = L1; Node *temp2 = L2; Node *t; while(temp2->Next!=NULL){ temp1 = L1; while(temp1->Next!=NULL){ if(temp1->Next->xuehao==temp2->Next->xuehao){ t = temp1->Next; temp1->Next = t->Next; t->Next = NULL; free(t); L1->xuehao--; break; } else{ temp1 = temp1->Next; } } temp2 = temp2->Next; } } int main() { Node *headnode1 = (Node*)malloc(sizeof(headnode1));//申请两个链表的头结点 Node *head1 = headnode1; head1->xuehao = 0; head1->score = 0; head1->Next = NULL; Node *headnode2 = (Node*)malloc(sizeof(headnode2)); Node *head2 = headnode2; head2->xuehao = 0; head2->score = 0; head2->Next = NULL; int a,b,xuehao,score; cin >> a >> b; for(int i=0;i<a;i++){ cin >> xuehao >> score; tailinsert(xuehao,score,head1); } for(int i=0;i<b;i++){ cin >> xuehao >> score; tailinsert(xuehao,score,head2); } deletenode(head1,head2); printlist(head1); return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:1292 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:904 |
罗列完美数 (C语言代码)浏览:519 |
1231题解(注意理解“输入多个测试实例”)浏览:830 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:608 |
母牛的故事 (C语言代码)浏览:519 |
【魔板】 (C++代码)浏览:1236 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:727 |
马拦过河卒 (C语言代码)浏览:1213 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:607 |