1069745273


私信TA

用户名:1069745273

访问量:5737

签 名:

Just do IT.

等  级
排  名 262
经  验 5780
参赛次数 3
文章发表 166
年  龄 0
在职情况 待业
学  校
专  业 计算机科学与技术

  自我简介:

#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 人评分

  评论区