leetcode-86. 分隔链表
题目:
代码:
#include <iostream>
using namespace std;
struct ListNode{
int val;
ListNode *next;
};
ListNode* partition(ListNode* head, int x) {
ListNode *small = new ListNode(0);
ListNode *smallHead = small;
ListNode *large = new ListNode(0);
ListNode *largeHead = large;
while(head){
if(head->val<x){
small->next=head;
small=small->next;
}else{
large->next=head;
large=large->next;
}
head=head->next;
}
large->next=nullptr;
samll->next=largeHead->next;
return smallHead->next;
}
int main(){
ListNode *head;
ListNode *res;
int x;
res=partition(head,x);
return 0;
}