In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Use the search binary tree to determine whether a word is spelled correctly:
Assuming that all words are inserted into the search binary tree according to the nature of the search tree, we determine whether a word is spelled correctly is to find out if the word exists in the tree (to find out if key exists).
/ * * Date: March 26th, 2018 14:42:54*Author: Meng*WebSite:msyci.com*QQ:3515955122**/# include # include # include # includetypedef char* KeyType;typedef char* ValueType Typedef struct BSTreeNode {struct BSTreeNode* _ left; struct BSTreeNode* _ right; KeyType _ key; ValueType _ value;} BSTreeNode;BSTreeNode * BuyTreeNode (KeyType x MagneValueType value) / / create node {BSTreeNode* node = (BSTreeNode*) malloc (sizeof (BSTreeNode)); assert (node); node- > _ key = x; node- > _ left = NULL; node- > _ right = NULL Node- > _ value = value; return node;} / / insert, search function int BSTreeNodeInsertR (BSTreeNode * * tree,KeyType key, ValueType value) / / insert of search tree {int tmp = 0; if (* tree = = NULL) {* tree = BuyTreeNode (key,value); return 0 } tmp = strcmp ((* tree)-> _ key,key); if (tmp > 0) return BSTreeNodeInsertR (& (* tree)-> _ left,key,value); else if (tmp_right,key,value); else return-1;} BSTreeNode* BSTreeNodeFindR (BSTreeNode* tree, KeyType key) / / find {int tmp = 0 If (! tree) {return NULL;} tmp = strcmp (tree- > _ key, key); if (tmp > 0) {return BSTreeNodeFindR (tree- > _ left, key);} else if (tmp)
< 0) { return BSTreeNodeFindR(tree->_ right, key);} else {return tree;}} void TestApplication () {BSTreeNode * tree = NULL; BSTreeNodeInsertR (& tree, "China", "China"); BSTreeNodeInsertR (& tree, "score", "result"); BSTreeNodeInsertR (& tree, "char", "character") BSTreeNodeInsertR (& tree, "int", "× × ×"); BSTreeNodeInsertR (& tree, "float", "floating point"); printf ("% s\ n", BSTreeNodeFindR (tree, "char")-> _ value); printf ("% s\ n", BSTreeNodeFindR (tree, "int")-> _ value) Printf ("% s\ n", BSTreeNodeFindR (tree, "float")-> _ value); printf ("% s\ n", BSTreeNodeFindR (tree, "China")-> _ value); printf ("% s\ n", BSTreeNodeFindR (tree, "score")-> _ value); printf ("% p\ n", BSTreeNodeFindR (tree, "double")) } int main (void) {TestApplication (); char c = getchar (); return 0;}
Running result:
Implement a simple Chinese and English dictionary
/ * * Date: March 26th, 2018 15:35:07*Author: Meng*WebSite:msyci.com*QQ:3515955122**/# include # include # include # includetypedef char* KeyType;typedef char* ValueType Typedef struct BSTreeNode {struct BSTreeNode* _ left; struct BSTreeNode* _ right; KeyType _ key; ValueType _ value;} BSTreeNode;BSTreeNode * BuyTreeNode (KeyType x MagneValueType value) / / create node {BSTreeNode* node = (BSTreeNode*) malloc (sizeof (BSTreeNode)); assert (node); node- > _ key = x; node- > _ left = NULL; node- > _ right = NULL Node- > _ value = value; return node;} / / insert, search function int BSTreeNodeInsertR (BSTreeNode * * tree,KeyType key, ValueType value) / / insert of search tree {int tmp = 0; if (* tree = = NULL) {* tree = BuyTreeNode (key,value); return 0 } tmp = strcmp ((* tree)-> _ key,key); if (tmp > 0) return BSTreeNodeInsertR (& (* tree)-> _ left,key,value); else if (tmp_right,key,value); else return-1;} BSTreeNode* BSTreeNodeFindR (BSTreeNode* tree, KeyType key) / / find {int tmp = 0 If (! tree) {return NULL;} tmp = strcmp (tree- > _ key, key); if (tmp > 0) {return BSTreeNodeFindR (tree- > _ left, key);} else if (tmp)
< 0) { return BSTreeNodeFindR(tree->_ right, key);} else {return tree;}} void TestApplication () {BSTreeNode * tree = NULL; BSTreeNodeInsertR (& tree, "China", "China"); BSTreeNodeInsertR (& tree, "score", "result"); BSTreeNodeInsertR (& tree, "char", "character") BSTreeNodeInsertR (& tree, "int", "× × ×"); BSTreeNodeInsertR (& tree, "float", "floating point"); printf ("% s\ n", BSTreeNodeFindR (tree, "char")-> _ value); printf ("% s\ n", BSTreeNodeFindR (tree, "int")-> _ value) Printf ("% s\ n", BSTreeNodeFindR (tree, "float")-> _ value); printf ("% s\ n", BSTreeNodeFindR (tree, "China")-> _ value); printf ("% s\ n", BSTreeNodeFindR (tree, "score")-> _ value); printf ("% p\ n", BSTreeNodeFindR (tree, "double")) } int main (void) {TestApplication (); char c = getchar (); return 0;}
Running result:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.