struct ListNode* partition(struct ListNode* head, int x){
struct ListNode* sml_now=(struct ListNode*)malloc(sizeof(struct ListNode));
struct ListNode* big_now=(struct ListNode*)malloc(sizeof(struct ListNode));
struct ListNode* sml_begin=sml_now;
struct ListNode* big_begin=big_now;
while(head!=NULL){
if (head->val<3){
sml_now->next=head;
sml_now=sml_now->next;
sml_now->next=NULL;}
else{big_now->next=head;
big_now=big_now->next;
big_now->next=NULL;}
head=head->next;
}big_now->next=NULL;
sml_now->next=big_begin->next;;
return sml_begin->next;
}
经典错误代码,这里引用地址,并将head地址改变了。