国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

二叉搜索樹 簡單函數歸納

2019-11-10 23:42:43
字體:
來源:轉載
供稿:網友

//搜索函數//————遞歸

struct node *Find(int x, struct node *t) { if (t != NULL) return NULL;         // 沒有找到x if (x > t -> data) return Find(x, t -> right); //右子樹尋找 else if (x < t -> data) return Find(x, t -> left);    //左子樹尋找 else if (x == t -> data) return t; //找到 x}

//搜索函數//——————迭代

struct node *Find(int x, struct node *t) { while(t)          { if (x > t -> data) t = t -> right; //右子樹尋找 else if (x < t -> data) t = t -> left;    //左子樹尋找 else if (x == t -> data) return t; //找到 x } return NULL; // 沒有找到x}

//查找最小元素//——————遞歸

struct node *findmin(x, struct node *t) { if (t == NULL) return NULL; else if (t -> left == NULL) return t; else return findmin(x, t -> left); }

//查找最小元素//——————迭代

struct node *findmin(x, struct node *t) { if (t != BULL) { while(t -> left != NULL) t = t -> left; } return t; }

//查找最大元素//————遞歸

struct node *findmax(x, struct node *t) { if (t == NULL) return NULL; else if (t -> right == NULL) return t; else return findmin(x, t -> right); }

//查找最大元素//————迭代

struct node *findmin(x, struct node *t) { if (t != BULL) { while(t -> right != NULL) t = t -> right; } return t; }

//插入函數//

struct node *Insert (int x, struct node *t) { if (t == NULL) //進行插入操作// { t = (struct node *)malloc(sizeof(struct node)); t -> data = x; t -> left = NULL; t -> right = NULL; } else if (x < t -> data) t -> left = Insert(x, t -> left); else if (x > t -> data) t -> right = Insert(x, t -> right); return t; }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 岐山县| 花莲县| 浦江县| 江川县| 绥滨县| 蒲江县| 河间市| 白城市| 抚顺市| 盐津县| 吉安市| 蓝山县| 汉沽区| 凤城市| 岳西县| 饶阳县| 滁州市| 隆昌县| 固安县| 兴城市| 宿松县| 惠来县| 时尚| 万州区| 临泉县| 新干县| 柏乡县| 柳江县| 沙洋县| 饶阳县| 济源市| 连山| 博客| 花垣县| 布拖县| 修水县| 富源县| 万年县| 康定县| 都安| 怀化市|