In this blog we will see how to do the traversal in a linked list.
class NodeF
{
int data;
NodeF next;
NodeF(int data)
{
this.data=data;
this.next=null;
}
}
public class TraversalLL {
public static void main(String args[])
{
NodeF head1=new NodeF(10);
NodeF head2=new NodeF(20);
NodeF head3=new NodeF(30);
head1.next=head2;
head2.next=head3;
head3.next=new NodeF(40);
print(head1);
}
public static void print(NodeF head)
{
NodeF curr=head;
while(curr !=null)
{
System.out.println(curr.data);
curr=curr.next;
}
}
}