2015-06-21 148 views
0

我想知道如何在Java中找到双向循环链表的最后一个节点,因为我想要查找循环链表中的节点的大小或数量。双向链表的大小

回答

1
public int getSize() { 
    int count = 0; 
    if (head == null) 
     return count; 
    else { 
     Node temp = head; 
     do { 
      temp = temp.getNextNode(); 
      count++; 
     } while (temp != head); 
    } 
    return count; 
} 
+0

万岁!它的工作.. 感谢您的帮助拉曼!!!! – ProgOptimal