Print the Elements of a Linked List

Sort by

recency

|

859 Discussions

|

  • + 0 comments
    def printLinkedList(head):
        current = head  
        while current:  
            print(current.data)
            current = current.next 
    
  • + 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;
        }
    }
    
  • + 0 comments

    Here is my simple python solution:

    def printLinkedList(head):
        print(head.data)
        if head.next is not None:
            printLinkedList(head.next)
    
  • + 0 comments

    There is a problem to use recursion in this problem?

  • + 0 comments

    Here is my c++ solution:

    void printLinkedList(SinglyLinkedListNode* head) {
        for ( ; head != NULL; head = head->next)
        {
            cout << head->data << endl;
        }
    }