2024 09 11
hw2
1
3 B
8 A
13 D
15 C
2
1
Node* merge(Node *p,Node *q){
if(p->val > q->val){
swap(p, q);
}
Node *ans=p, *last=p;
p=p->next;
while(p && q){
if(p->val > q->val){
swap(p, q);
}
last->next=p;
last=p;
p=p->next;
}
if(p){
last->next=p;
}
else{
last->next=q;
}
return ans;
}
2
Node* merge(Node *p,Node *q){
if(p->val > q->val){
swap(p, q);
}
Node *ans=p, *last=p;
p=p->next;
while(p && q){
if(p->val > q->val){
swap(p, q);
}
last->next=p;
last=p;
p=p->next;
}
if(p){
last->next=p;
}
else{
last->next=q;
}
ans=reverse(ans);
return ans;
}
Node* reverse(Node *p){
Node *n=p->next, *nn;
p->next=NULL;
while(n){
nn=n->next;
n->next=p;
p=n;
n=nn;
}
return p;
}
7
Node* reverse(Node *p){
Node *n=p->next, *nn;
p->next=NULL;
while(n){
nn=n->next;
n->next=p;
p=n;
n=nn;
}
return p;
}
标签:Node,last,nn,val,ds2,next,ans
From: https://www.cnblogs.com/suxxsfe/p/18414481