版本比较
平衡树模板及注解
正文
增加 4 行删除 4 行
121 行未改动全部展开12212312412512612712812913031 行未改动162163164165166167168169170236 行未改动全部展开407408409410411412413414415210 行未改动全部展开626627628629630631632633121 行未改动全部展开else{cout<<"404:未找到"<<endl;}ElemType deletekey;cout<<"删除元素:";cin>>deletekey;DeleteBST(T,deletekey);if(SearchBST(T,deletekey)){cout<<"找到了"<<endl;31 行未改动typedef struct AVLNode{int data,height;//节点内容 节点高度struct AVLNode *lchild;struct AVLNode *rchild;//左右子节点指针}*AVLTree;//实际上就是把AVLNode*这个指针类型重命名为AVLTree,乐死我了多长时间了才看懂int Height(AVLTree T){if(!T){236 行未改动全部展开}int get_pre(int v){find(v);int x=root;if(tr[x].v<v){//因为如果树中不存在v,find会找到第一个比它大或小的元素并转上根节点,如果根比v小说明根就是前驱return root;}x=tr[x].s[0];//去比自己小的子树while(tr[x].s[1]){//在比v小的子树中找最大的就是前驱了210 行未改动全部展开//freopen(".in","r",stdin);//freopen(".out","w",stdout);ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);return 0;}```121 行未改动全部展开12212312412512612712812913031 行未改动162163164165166167168169170236 行未改动全部展开407408409410411412413414415210 行未改动全部展开626627628629630631632633121 行未改动全部展开else{cout<<"404:未找到"<<endl;}ElemType deletekey;cout<<"删除元素:";cin>>deletekey;DeleteBST(T,deletekey);if(SearchBST(T,deletekey)){cout<<"找到了"<<endl;31 行未改动typedef struct AVLNode{int data,height;//节点内容 节点高度struct AVLNode *lchild;struct AVLNode *rchild;//左右子节点指针}*AVLTree;//实际上就是把AVLNode*这个指针类型重命名为AVLTree,乐死我了多长时间了才看懂int Height(AVLTree T){if(!T){236 行未改动全部展开}int get_pre(int v){find(v);int x=root;if(tr[x].v<v){//因为如果树中不存在v,find会找到第一个比它大或小的元素并转上根节点,如果根比v小说明根就是前驱return root;}x=tr[x].s[0];//去比自己小的子树while(tr[x].s[1]){//在比v小的子树中找最大的就是前驱了210 行未改动全部展开//freopen(".in","r",stdin);//freopen(".out","w",stdout);ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);return 0;}```