如何使用BST实施dicitonary [英] how to implement a dicitonary using BST

查看:52
本文介绍了如何使用BST实施dicitonary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下方式制作BST





i我正在编写菜单驱动程序来插入,删除和搜索单词在

字典中。



  typedef   struct 节点
{
字符串字;
字符串含义;
struct node * left;
struct node * right;
struct node * parent;
};





树本身由指向
$ b $根节点的指针表示b树。单词/含义字段存储对应其含义的单词

此字典;左边和右边的指针分别指向这个节点的左边和右边的子节点,而父节点指向这个节点的父节点(如果这些节点,它们将获取值为NULL的
不存在)



所以我应该如何将txt文件中的单词存储到此树中。

解决方案

< blockquote>嗯,你真的不需要父成员。



欲了解更多信息,请阅读这篇文章(或其他你可能会发现的内容)

C ++中的二叉树:第1部分 [ ^ ]


然后你只需要按正确的顺序排列节点。 br />
除非是练习,否则你也可以考虑使用 std :: map< string,string> std :: unordered_map< string,string>


i am using following aproach to make a BST


i am writing a menu driven program to insert, delete and search a word in the
dictionary.

typedef struct node
{
    String word;
    String Meaning;
    struct node *left;
    struct node *right;
    struct node *parent;
};



The tree itself is represented by a pointer to the root node of the
tree. The word/meaning field stores the word corresponding its meaning of
this dictionary; the left and right pointers point to the left and right children
of this node respectively while parent points to the parent of this node (they
will take value NULL if these nodes do not exist)

so how i should store the word from a txt file to this tree.

解决方案

Hmm, you don't really need the parent member.

For more info, read this article (or others you might find)
Binary Trees in C++: Part 1[^]


Then you just need to arrange the nodes in the correct order.
Unless it is an exercise, you may also consider using std::map<string, string> or std::unordered_map<string, string>.


这篇关于如何使用BST实施dicitonary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆