2015-06-21 202 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