Programming/Data Structure

[Hackerrank] PrintLinkedList

읽고 쓰는 개발자 2020. 12. 2. 22:34

www.hackerrank.com/challenges/print-the-elements-of-a-linked-list/problem

Print the Elements of a Linked List | HackerRank

Get started with Linked Lists!

www.hackerrank.com

package exam.complete;

import exam.SinglyLinkedListNode;

//https://www.hackerrank.com/challenges/print-the-elements-of-a-linked-list/problem
public class PrintLinkedList {
    static void printLinkedList(SinglyLinkedListNode head) {
        while(head != null) {
            System.out.println(head.data);
            head = head.next;
        }
    }
}