We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Linked Lists
  4. Print the Elements of a Linked List

Print the Elements of a Linked List

Problem
Submissions
Leaderboard
Discussions
Editorial

This challenge is part of a MyCodeSchool tutorial track and is accompanied by a video lesson.


This is an to practice traversing a linked list. Given a pointer to the head node of a linked list, print each node's element, one per line. If the head pointer is null (indicating the list is empty), there is nothing to print.

Function Description

Complete the printLinkedList function in the editor below.

printLinkedList has the following parameter(s):

  • SinglyLinkedListNode head: a reference to the head of the list

Print

  • For each node, print its value on a new line (console.log in Javascript).

Input Format

The first line of input contains , the number of elements in the linked list.
The next lines contain one element each, the values for each node.

Note: Do not read any input from stdin/console. Complete the printLinkedList function in the editor below.

Constraints

  • , where is the element of the linked list.

Sample Input

2
16
13

Sample Output

16
13

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 on a new line.

Author

harsha_s

Difficulty

Easy

Max Score

5

Submitted By

372878

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature