Print the Elements of a Linked List

Sort by

recency

|

854 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/t3gCqS1F24w

    void printLinkedList(SinglyLinkedListNode* head) {
    
        while(head != nullptr){
            cout << head -> data << endl;
            head = head -> next;
        }
    }
    
  • + 1 comment

    Swift template code is broken. (compile error)

  • + 0 comments

    c solution


    void printLinkedList(SinglyLinkedListNode* head) { SinglyLinkedListNode* current = head;

    // Traverse the linked list and print each node's value
    while (current != NULL) {
        printf("%d\n", current->data);
        current = current->next;  // Move to the next node
    }
    

    }

  • + 0 comments

    C++ Solution

    void printLinkedList(SinglyLinkedListNode* head) {
        SinglyLinkedListNode* p=head;
        while(p!=0){
            cout<<p->data<<endl;
            p=p->next;
        }
    }
    
  • + 0 comments

    Here is my c++ solution in simple way , you can watch the explanation

     SinglyLinkedListNode* temp=head;
        while(temp!=nullptr){
            cout<<temp->data<<"\n";
            temp=temp->next;
        }