Last active
February 20, 2018 02:05
-
-
Save vardanator/712a683f03fea1b02c9b828b288a9a41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // struct ListNode { | |
| // ListNode* next; | |
| // T item; | |
| // }; | |
| void TraverseRecursive(ListNode* node) // starting node, most commonly the list 'head' | |
| { | |
| if (!node) return; // stop | |
| std::cout << node->item; | |
| TraverseRecursive(node->next); // recursive call | |
| } | |
| void TraverseIterative(ListNode* node) | |
| { | |
| while (node) { | |
| std::cout << node->item; | |
| node = node->next; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment