/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* partition(struct ListNode* head, int x){
struct ListNode* small=malloc(sizeof(struct ListNode));
struct ListNode* smallHead=small;
struct ListNode* high=malloc(sizeof(struct ListNode));
struct ListNode* highHead=high;
while(head){
if(head->val<x){
small->next=head;
small=head;
head=head->next;
}
else if(head->val>=x){
high->next=head;
high=head;
head=head->next;
}
}
high->next=NULL;
small->next=highHead->next;
return smallHead->next;
}