文章

16

粉丝

134

获赞

0

访问

3.3k

头像
链表合并 题解:0%,不知道哪里有问题,谢谢小伙伴们帮我看看
P1025 贵州大学2019机试
发布于2024年3月24日 16:17
阅读数 220

#include<bits/stdc++.h>
using namespace std;
struct node{
    int n;
    struct node *next;
};
//创建链表
struct node* create(int n,int a[105]){
    struct node* head = (struct node*)malloc(sizeof(struct node));
    head->next=NULL;
    struct node* p = head;
    for(int i=0;i<n;i++){
        struct node* now=(struct node*)malloc(sizeof(struct node));
        now->n=a[i];
        now->next=NULL;
        p->next=now;
        p=now;
    }
    return head;
}
//之间将两个链表拼起来再进行冒泡排序
struct node*combine(struct node *head1,struct node*head2,int s1,int s2){
    struct node*p=head1;
    struct node*q=head2;
    while(p->next!=NULL)
        p=p->next;
    p->next=q->next;
    for(int i=0;i<s1...

登录查看完整内容


登录后发布评论

2 条评论
snake
2024年3月24日 18:01

和刚刚那道题同样的问题,建议创建链表不要空一个头结点出来,可以看一下其他同学的。

赞(0)

为欢几何 : 回复 snake: 谢谢啦

2024年3月28日 09:10