【问题标题】:How to print out only the unique words in a tree with in order traversal如何使用顺序遍历仅打印树中的唯一单词
【发布时间】:2015-05-01 04:35:23
【问题描述】:

这个问题基本上说明了一切,但这就是我目前所知道的

void inorder(Node *root)
{
    int come_back_later=0;

    if(come_back_later)
    {
       //part where i print out only the unique words from the tree
    }

    if(root==NULL)
        return;

    inorder(root->left);
    cout<<root->word<<": it's word count is: "<< root->count<<endl;
    inorder(root->right);

}

我的想法是我先进行中序遍历,然后打印出所有单词以及它们的计数。但是后来我想稍后重新访问该遍历并仅打印出唯一的单词,但我不知道如何为此创建算法代码。我所知道的,如果字数是 1,那么这个词必须是唯一的,因为它只在文件中出现过一次。如果有人可以帮助我,那就太好了。

【问题讨论】:

    标签: binary-tree unique traversal inorder


    【解决方案1】:

    你需要将它与树中所有剩余的节点进行比较。只需创建一个新数组并将您遇到的单词与计数一起存储即可。在您的下一次遍历而不是在那里检查计数时,检查数组并在计数为 1 时打印。

    【讨论】:

      猜你喜欢
      • 2015-03-28
      • 1970-01-01
      • 2020-07-16
      • 2022-01-14
      • 2020-02-18
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      • 2020-04-01
      相关资源
      最近更新 更多