Print the Elements of a Linked List

Sort by

recency

|

869 Discussions

|

  • + 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;
        }
    }
    
  • + 0 comments

    cpp

    void printLinkedList(SinglyLinkedListNode* head) {
    
        auto current = head;
    		while(current){
            std::cout << current->data << std::endl;
            current = current->next;
        }
        
    }
    
  • + 0 comments

    Just like layers of river rocks stack up beneath the earth over time, each node in a linked list connects to the next solid, grounded, and part of a bigger structure.

  • + 0 comments

    Here's a solution in C#

    static void printLinkedList(SinglyLinkedListNode head) {
            while(head != null){
                Console.WriteLine(head.data);
                head = head.next;
            }
        }