求单链表有效节点的个数

 关于单链表的实现 请参考blog

    /*
     * @param herd 链表的头节点
     * @return 返回有效节点的个数
     * */
    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;
    }

猜你喜欢

转载自blog.csdn.net/weixin_38289787/article/details/103266591