insertNode function

dynamic insertNode(
  1. dynamic i,
  2. dynamic x,
  3. dynamic y,
  4. dynamic last,
)

Implementation

insertNode(i, x, y, last) {
  var p = Node(i, x, y);

  if (last == null) {
    p.prev = p;
    p.next = p;
  } else {
    p.next = last.next;
    p.prev = last;
    last.next.prev = p;
    last.next = p;
  }

  return p;
}