int?MaxDistanceBetweenVertices(VertexedLinkedListNode root) { int count = 0; int?start = null, end = null; VertexedLinkedListNode cur = root; while (cur != null) { count++; if (cur.IsVertex) { if (start == null) { start = count; } else { end = count; } } cur = cur.next; } return(end - start); }
public VertexedLinkedListNode(int data, VertexedLinkedListNode next, bool IsVertex) { this.data = data; this.next = next; this.IsVertex = IsVertex; }
int? MaxDistanceBetweenVertices(VertexedLinkedListNode root) { int count = 0; int? start = null, end = null; VertexedLinkedListNode cur = root; while (cur != null) { count++; if (cur.IsVertex) { if (start == null) start = count; else end = count; } cur = cur.next; } return end - start; }