第十二章:二叉查找树(1)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                第十二章:二叉查找树(1)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                二叉查找樹的基本操作
#include <iostream> #include <stack>using namespace std;stack<TreeNode *> s;typedef int Data;struct TreeNode{Data data;TreeNode *parent;TreeNode *left;TreeNode *right; };//創建一顆查找二叉樹 TreeNode *Create_Tree(int num){TreeNode *p=(TreeNode *)malloc(sizeof(TreeNode));TreeNode *root,*child,*parent;child=root=p;p->parent=p->left=p->right=NULL;cin>>root->data;int i=0;while (++i<num){TreeNode *p=(TreeNode *)malloc(sizeof(TreeNode));p->parent=p->left=p->right=NULL;cin>>p->data;child=root;while (child){parent=child;if (p->data>child->data){child=child->right;}else{child=child->left;}}if (p->data>parent->data){parent->right=p;p->parent=parent;}else{parent->left=p;p->parent=parent;}}return root; }TreeNode *Tree_Search(TreeNode *t,int key){while (t&&t->data!=key){if (t->data>key){t=t->left;}else{t=t->right;}}return t; }TreeNode *Minimum(TreeNode *t){while (t->left){t=t->left;}return t; }TreeNode *Maximum(TreeNode *t){while (t->right){t=t->right;}return t; }TreeNode *Tree_Successor(TreeNode *t){if (t->right){return Minimum(t->right);}else{while (t->parent&&t->parent->right==t){t=t->parent;}return t->parent;} }TreeNode *Tree_Predecessor(TreeNode *t){if (t->left){t=t->left;while (t->right){t=t->right;}return t;}else if (t->parent){return t->parent; } }
轉載于:https://www.cnblogs.com/lsf90/p/3147147.html
總結
以上是生活随笔為你收集整理的第十二章:二叉查找树(1)的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 桥牌笔记-防止阻塞
- 下一篇: 挂载WebDav提供的网络存储----C
