Skip to main content

Program in Java: To count the number of nodes in a linkedlist

 int countNodes() //to display the number of nodes

    {

        int c=0;

        Node ptr=this;

        while(ptr.link!=null)

        {

            c=c+1;

            ptr=ptr.link;

        }

        c=c+1;

        return c;

    }

Popular posts from this blog