new a node, then pre.next = node
algorithm from answer, quite math related