Skip to content

Instantly share code, notes, and snippets.

@vardanator
Last active February 20, 2018 02:05
Show Gist options
  • Select an option

  • Save vardanator/712a683f03fea1b02c9b828b288a9a41 to your computer and use it in GitHub Desktop.

Select an option

Save vardanator/712a683f03fea1b02c9b828b288a9a41 to your computer and use it in GitHub Desktop.
// 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