统计单链表节点的有效个数
public static int getLength(heroNode head){
if (head.next == null){
return 0;
}
int length = 0;
heroNode cur = head.next;
while (cur != null){
length++;
cur = cur.next;
}
return length;
}
体会了head是地址的指向以后就都清楚了,爽