• + 0 comments

    c++ solution using stack

    void reversePrint(SinglyLinkedListNode* llist) {
        std::stack<int> stack;
        SinglyLinkedListNode* node = llist;
        while (node != NULL) {
            stack.push(node->data);
            node = node->next;
        }
        while (!stack.empty()) {
            printf("%d\n", stack.top());
            stack.pop();
        }
    }