就是合并两个有序数列,变成一个新的有序数列
我刚刚学链表,然后就想用链表做一下,巩固一下,然后就不知道怎么连链表了啊啊啊
#include<bits/stdc++.h>
using namespace std;
int n,m;
struct Node{
int value;
Node *next,*prev;
}a1[100001],a2[100001],*head1,*head2;
//_________________________________________
void Hblin(){
Node *p=head2;
for(Node *t=head1;t;t=t->next){
while(t->value>p->value){
if(t==head1){
p->next=head1;
head1=p;
}
else{
p->prev=t->prev;
p->next=t;
}
p=p->next;
}
}
}
//__________________________________________
int main(){
scanf("%d%d",&n,&m);
head1=NULL,head2=NULL;
Node *p1,*p2;
for(int i=1;i<=n;i++){
scanf("%d",&a1[i].value);
if(head1==NULL){
head1=&a1[i];
p1=head1;
}
else{
p1->next=&a1[i];
p1=p1->next;
}
}
for(int i=1;i<=m;i++){
scanf("%d",&a2[i].value);
if(head2==NULL){
head2=&a2[i];
p2=head2;
}
else{
p2->next=&a2[i];
p2=p2->next;
}
}
Hblin();
for(Node *t=head1;t;t=t->next){
printf("%d ",t->value);
}
return 0;
}
在Hblin函数里面,我认为if和while的判断都是对的,然后我用小样例测了一下,结果发现没有连起来,所以各位只用帮我检查一下Hblin函数里面我连节点的时候哪里又问题啊
求求各位了