You are viewing a single comment's thread. Return to all comments →
C++ void reversePrint(SinglyLinkedListNode* _list) { if (!_list) { return; } std::vector nums; SinglyLinkedListNode* temp = _list; while (temp) { nums.push_back(temp->data); temp = temp->next; } for (auto it = nums.rbegin(); it != nums.rend(); ++it) { std::cout << *it << "\n"; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Print in Reverse
You are viewing a single comment's thread. Return to all comments →
C++ void reversePrint(SinglyLinkedListNode* _list) { if (!_list) { return; } std::vector nums; SinglyLinkedListNode* temp = _list; while (temp) { nums.push_back(temp->data); temp = temp->next; } for (auto it = nums.rbegin(); it != nums.rend(); ++it) { std::cout << *it << "\n"; } }