Https www hackerrank com challenges print the elements of a linked list problem

X

Privacy & Cookies

This site uses cookies. By continuing, you agree to their use. Learn more, including how to control cookies.

Got It!
Advertisements

Sample Input

2 16 13

Sample Output

16 13

In this post we will be seeing how to Print the Elements of a Linked List Hackerrank Solution

Explanation

There are two elements in the linked list. They are represented as 16 -> 13 -> NULL. So, the printLinkedList function should print 16 and 13 each in a new line.

Code:

static void printLinkedList(SinglyLinkedListNodehead){

SinglyLinkedListNodetemp=head;

while(temp!=null){

System.out.println(temp.data);

temp=temp.next;

}

}

Hope you guys find this code helpfull, Happy Coding

Thank You..!

Advertisements

Share this: