Inorder Traversal Non-ending recursion

#include <iostream> #include "TreeNode.h" void inorder_print(TreeNode * root){ // print out the tree content in inorder traversal while(root != nullptr){ std::cout << root->val << std::endl; inorder_print(root->left); inorder_print(root->right); } } int main() { TreeNode * root = new TreeNode(0); root->right = new TreeNode(2); root->right->right = new TreeNode(3); inorder_print(root); }
Output is 3333333....

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.