educative.io

Iterative code implamantion in eclipse!

hi, which libray using in this code i must import node or creating class node!!

class Solution {

    /* Returns count of nodes in linked list */

    public static int lengthOfList(Node head)

    {

        int count = 0;

        Node temp = head;

        while (temp != null) {

            count++;

            temp = temp.next;

        }

        return count;

    }

 

    public static void main(String[] args)

    {

        /* Start with the empty list */

        LinkedList llist = new LinkedList();

        llist.push(1);

        llist.push(3);

        llist.push(1);

        llist.push(2);

        llist.push(1);

 

        System.out.println("Count of nodes is = " + lengthOfList(llist.head));

    }

}

Course: https://www.educative.io/collection/10370001/5996180548878336
Lesson: https://www.educative.io/collection/page/10370001/5996180548878336/5380990203592704

Hi @ayman!!
Thank you for reaching out to the Educative Team. Here, you need to create a class node in order to proceed with the task. To do so, you can start by defining the class with the keyword “class” followed by the class name, like this:

class Node:

From there, you can add any attributes or methods that are needed for your program. If you need further guidance or have any other questions, please don’t hesitate to let us know. We’re here to help!
Happy Learning :blush:

1 Like

ok, thank you very much