代码:
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* partition(struct ListNode* head, int x) {
typedef struct ListNode lide;
lide*cur=head;
int k=0;
int *hash=malloc(sizeof(int)*210);//创建数组 存入节点值
while(cur)
{hash[k++]=cur->val;
cur=cur->next;
}
cur=head;
for(int i=0;i<k;i++)//找到小于X的数
{if(hash[i]<x)
{cur->val=hash[i];
cur=cur->next;
}
}
for(int i=0;i<k;i++)//找到大于等于X的数
{if(hash[i]>=x)
{cur->val=hash[i];
cur=cur->next;
}
}
return head;
}