code: public Segment pop() {
      Segment result = next != this ? next : null;
      prev.next = next;
      next.prev = prev;
      next = null;
      prev = null;
      return result;
    }
docs: Removes this segment of a circularly-linked list and returns its successor.
  Returns null if the list is now empty.