【问题标题】:What does this Binary search tree function do?这个二叉搜索树函数有什么作用?
【发布时间】:2017-11-26 17:51:41
【问题描述】:

我想知道这个函数有什么作用,这段代码可能的输出是什么?

void TreeType::Function()
{ 
Queue<TreeNode*> q;
TreeNode* node;
if (root!= NULL) {
q.Enqueue(root);

do {
    q.Dequeue(node);
    cout << node->info << endl;

    if (node->left) 
   { q.Enqueue(node->left); }

    if (node->right) 
   { q.Enqueue(node->right); }

while (!q.IsEmpty()); }

【问题讨论】:

  • 你执行了吗?
  • 是的,但我不明白
  • 这会逐层打印树的节点。

标签: function data-structures output binary-search-tree


【解决方案1】:

此功能类似于任何树的级别顺序遍历。 虽然缺少很多结尾分号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    • 2017-09-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    相关资源
    最近更新 更多