1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| var ListPartition=(head,pivot)=>{ let sH=null,sT=null,eH=null,eT=null,mH=null,mT=null; let next=null; while(head!==null){ next=head.next; head.next=null; if(head.value<pivot){ if(sH===null){ sH=head; sT=head; }else{ sT.next=head; sT=head; } }else if(head.value===pivot){ if(eH===null){ eH=head; eT=head; }else{ eT.next=head; eT=head; } }else{ if(mH==null){ mH=head; mT=head; }else{ mT.next=head; mT=head; } } head=next; } if(sT!==null){ sT.next=eH; eT=eT===null?sT:eT; } if(eT!==null){ eT.next=mH; } return sH!==null?sH:(eH!==null?eH:mH) }
|