Print the Elements of a Linked List Hackerrank Solution

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(SinglyLinkedListNode head) {       

 SinglyLinkedListNode temp = head;       

 while(temp != null){          

  System.out.println(temp.data);     

       temp = temp.next;    

    }

    }

Hope you guys find this code helpfull, Happy Coding

Thank You..!



Categories: HackerRank Questions

Tags: , , , ,

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: