insertBefore method

VertexList insertBefore(
  1. VertexNode target,
  2. VertexNode vertex
)

Implementation

VertexList insertBefore(VertexNode target, VertexNode vertex) {
  vertex.prev = target.prev;
  vertex.next = target;

  if (vertex.prev == null) {
    head = vertex;
  } else {
    vertex.prev!.next = vertex;
  }

  target.prev = vertex;

  return this;
}