>>590
list partition(list p, int x) {
  list head, tail, t;
  if (p == NULL) return NULL;
  head = tail = p;
  p = p->next;
  while (p != NULL) {
    t = p;
    p = p->next;
    if (t->val <= x) {
      t->next = head;
      head = t;
    } else {
      tail->next = t;
      tail = t;
    }
  }
  tail->next = NULL;
  return head;
}
pの頭から要素を取り出し、x以下であれば新しく作るリストの頭へ、
そうでなければ尻尾へ加える。