The meaning is to put those greater than k in front, and those less than k in the back, but the relative order among the group greater than k remains unchanged, and the relative order among the group less than k also remains unchanged.
classSolution { public: ListNode *partition(ListNode *head, int x) { ListNode *virt_node = new ListNode; virt_node->next = head;
ListNode *prev = virt_node, *p, *tmp; while (prev->next != nullptr && prev->next->val < x) { prev = prev->next; //Find the predecessor node of the first node greater than or equal to x }
if (prev->next == nullptr) { //all vals < x return head; } p = prev;