标签:style blog color sp on div log bs 代码
TreeNode a;
while (a.hasNext())
visit(a.next());
}"
问:给TreeNode写Iterator,使得以上代码可以in order traversal
class TreeNode { TreeNode *root; public: bool hasNext() { return root!=NULL || !stack.empty(); } TreeNode * next() { TreeNode * ret = NULL; while(hashNext()) { if(root) { stack.push(root); root = root->left; } else { root = stack.top(); stack.pop(); ret = root; root = root->right; return ret; } } return NULL; } };
Tree inorder traversal Iterator
标签:style blog color sp on div log bs 代码
原文地址:http://www.cnblogs.com/jobfindingnotes/p/4117873.html