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..!