class Solution {
public:
ListNode* partition(ListNode* head, int x) {
if (head == NULL) return head;
ListNode* mid = NULL;
ListNode* curNode = head;
if (head->val < x) mid = curNode;
while (curNode->next != NULL) {
ListNode* next = curNode->next;
if (next->val >= x) {
curNode = curNode->next;
}
else {
curNode->next = next->next;
if (mid == NULL) {
next->next = head;
head = next;
}
else {
next->next = mid->next;
mid->next = next;
}
mid = next;
if (curNode->val < x) curNode = curNode->next;
}
}
return head;
}
};
int main()
{
Solution sol;
vector<int> input = {2,1};
ListNode *head = createListNode(input);
int x=2;
printLinkedList(sol.partition(head, x));
return 0;
}