Print the Elements of a Linked List

Sort by

recency

|

872 Discussions

|

  • + 0 comments

    solved using recursion

    function printLinkedList(head) {``
       if(head === null) return;
       console.log(head.data)
       printLinkedList(head.next)
    
    }
    
  • + 0 comments

    i cant delete the program in this page nor i can write new one what should i do in hackerrank

  • + 0 comments

    def printLinkedList(head):

    current = head
    while current is not None:
        print(current.data)
        current = current.next
    
  • + 0 comments

    void printLinkedList(SinglyLinkedListNode* head) {

    auto current = head;
        while(current){
        std::cout << current->data << std::endl;
        current = current->next;
    }
    

    }

  • + 0 comments

    JavaScript (Node.js)

    function printLinkedList(head) {
        while (head) {
            console.log(head.data);
            head = head.next;
        }
    }