In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.