link (r, t1@(NODE x1 c1)) (_, t2@(NODE x2 c2)) =
  if x1 <= x2 then (r + 1, NODE x1 (t2:c1)) else (r + 1, NODE x2 (t1:c2))
link (r, t1@(NODE x1 c1)) (_, t2@(NODE x2 c2)) =
  if x1 <= x2 then (r + 1, NODE x1 (t2:c1)) else (r + 1, NODE x2 (t1:c2))
link (r, t1@(NODE x1 c1)) (_, t2@(NODE x2 c2)) =
  if x1 <= x2 then (r + 1, NODE x1 (t2:c1)) else (r + 1, NODE x2 (t1:c2))