欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

搜索二叉樹之字典實現(xiàn)

    利用搜索二叉樹判斷一個單詞是否拼寫正確:

古丈ssl適用于網站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!

    假設把所有單詞都按照搜索樹的性質插入到搜索二叉樹中,我們判斷一個單詞拼寫是否正確就是在樹中查找該單詞是否存在(查找key是否存在)。

/*****************************************
*Date:2018年3月26日14:42:54
*Author: Meng
*WebSite:msyci.com
*QQ:3515955122
*****************************************/

# include <stdio.h>
# include <stdlib.h>
# include <string.h>
#include<assert.h>

typedef char* KeyType;
typedef char* ValueType;

typedef struct BSTreeNode
{
	struct BSTreeNode*  _left;
	struct BSTreeNode*  _right;
	KeyType  _key;
	ValueType _value;
}BSTreeNode;

BSTreeNode *BuyTreeNode(KeyType x,ValueType value ) //創(chuàng)建節(jié)點
{
	BSTreeNode *node = (BSTreeNode*)malloc(sizeof(BSTreeNode));
	assert(node);

	node->_key = x;
	node->_left = NULL;
	node->_right = NULL;
	node->_value = value;

	return node;
}

//插入、查找函數(shù)
int BSTreeNodeInsertR(BSTreeNode **tree,KeyType key, ValueType value) //搜索樹的插入
{
	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<0)
		return BSTreeNodeInsertR(&(*tree)->_right,key,value);
	else
		return -1;
}

BSTreeNode*  BSTreeNodeFindR(BSTreeNode* tree, KeyType  key)  //查找
{
	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","中國");
		BSTreeNodeInsertR(&tree,"score","成績");
		BSTreeNodeInsertR(&tree,"char","字符");
		BSTreeNodeInsertR(&tree,"int","×××");
		BSTreeNodeInsertR(&tree,"float","浮點型");

		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;
}

運行結果:

搜索二叉樹之字典實現(xiàn)

實現(xiàn)簡單的中英文字典


/*****************************************
*Date:2018年3月26日15:35:07
*Author: Meng
*WebSite:msyci.com
*QQ:3515955122
*****************************************/

# include <stdio.h>
# include <stdlib.h>
# include <string.h>
#include<assert.h>

typedef char* KeyType;
typedef char* ValueType;

typedef struct BSTreeNode
{
	struct BSTreeNode*  _left;
	struct BSTreeNode*  _right;
	KeyType  _key;
	ValueType _value;
}BSTreeNode;

BSTreeNode *BuyTreeNode(KeyType x,ValueType value ) //創(chuàng)建節(jié)點
{
	BSTreeNode *node = (BSTreeNode*)malloc(sizeof(BSTreeNode));
	assert(node);

	node->_key = x;
	node->_left = NULL;
	node->_right = NULL;
	node->_value = value;

	return node;
}

//插入、查找函數(shù)
int BSTreeNodeInsertR(BSTreeNode **tree,KeyType key, ValueType value) //搜索樹的插入
{
	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<0)
		return BSTreeNodeInsertR(&(*tree)->_right,key,value);
	else
		return -1;
}

BSTreeNode*  BSTreeNodeFindR(BSTreeNode* tree, KeyType  key)  //查找
{
	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","中國");
		BSTreeNodeInsertR(&tree,"score","成績");
		BSTreeNodeInsertR(&tree,"char","字符");
		BSTreeNodeInsertR(&tree,"int","×××");
		BSTreeNodeInsertR(&tree,"float","浮點型");

		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;
}

運行結果:

搜索二叉樹之字典實現(xiàn)

網頁題目:搜索二叉樹之字典實現(xiàn)
鏈接分享:http://www.aaarwkj.com/article0/igosoo.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供Google、標簽優(yōu)化微信小程序網站收錄、App設計、商城網站

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

網站建設網站維護公司
欧美一区二区三区东京热| 天美传媒剧国产在线观看| 少妇被啪出水在线视频| 久久久久精品久久久| 蜜臀av人妻一区二区三区| 狠狠久久五月综合色和啪| 国产原创传媒在线观看| 亚洲中文字幕高清无二区| 婷婷六月亚洲激情综合| 亚洲成人精品青青香蕉| 日本午夜精品在线观看| 日韩亚洲国产激情一区二区| 国产精品亚洲精品日韩在线| 精品中文人妻中文字幕| 日韩欧美国产一区二区精品| 日韩av在线观看大全| 2018在线不卡爱视频| 亚洲精品一区二区日本| av在线播放网址网站| 亚洲ve中文字幕久久一区二区| 日韩av在线高清播放| 日韩不卡区高清在线视频| 最新国产精品欧美激情| 色哟哟哟哟免费观看视频| 另类视频网站在线观看| 亚洲免费成人一区二区| 女人的天堂亚洲的天堂欧美| 久久99热最新地址获取| 亚洲最大五月六月丁香婷婷| 精品毛片在线播放网站不卡| 男人的天堂av最新版本| 久久久久亚洲av成人网人| 国产天美剧情av一区二区| 亚洲日本精品一区二区三区| 亚洲欧美日韩精品成人| 国产精品日韩欧美一区二区| 国产欧美日韩另类视频| 久久精品国产亚洲av麻豆她| 国产叼嘿一区二区视频| 国产成人大片一区二区三区| 夫妻性生活免费的视频|