Sort by

recency

|

973 Discussions

|

  • + 0 comments

    solution

    function reversePrint(llist) { // Write your code here if (llist === null) { return } else { // reverse the list let current = llist; let prev = null;

        while (current !== null) {
            let next = current.next;
            current.next = prev;
            prev = current;
            current = next;
        };
    
        //print the reverse list
        let reversed = prev;
        for (; reversed !== null; reversed = reversed.next) {
            console.log(reversed.data);
        };
    
    }
    

    }

  • + 0 comments

    Here is my c++ solution, you can watch the vidéo explanation here : https://youtu.be/WO7Uz7sQML4

    void reversePrint(SinglyLinkedListNode* llist) {
        if(llist == nullptr) return;
        reversePrint(llist->next);
        cout << llist->data << endl;
    }
    
  • + 0 comments

    Here is my recursive call on next node for JAVA

    public static void reversePrint(SinglyLinkedListNode llist) {
        if(llist == null) {
            return;
        }
    
        reversePrint(llist.next);
    
        System.out.println(llist.data);
    }
    
  • + 0 comments

    Python recursion Solution def reversePrint(llist): if llist.next is None: print(llist.data) else: reversePrint(llist.next) print(llist.data)

  • + 0 comments

    Did it with simple vector in C++

    void reversePrint(SinglyLinkedListNode* llist) {
        vector<int> arr;
        SinglyLinkedListNode* temp = llist;
        while(temp != NULL){
            arr.push_back(temp->data);
            temp = temp->next;
        }
        for(int i = arr.size() - 1; i >= 0; i--){
            cout << arr[i] << endl;
        }
    }