【数据结构】红黑树的实现(2)
发布时间:2021-04-02 00:29 所属栏目:53 来源:网络整理
导读:#include iostream#include "RBTree.h"using namespace std;int main(){ int a[]= {200,250,122,77,75,80,99,70,110,120,300}; int i; int ilen = (sizeof(a)) / (sizeof(a[0])) ; RBTreeint* tree=new RBTreeint()
#include <iostream> #include "RBTree.h" using namespace std; int main() { int a[]= {200,250,122,77,75,80,99,70,110,120,300}; int i; int ilen = (sizeof(a)) / (sizeof(a[0])) ; RBTree<int>* tree=new RBTree<int>(); for(i=0; i<ilen; i++) { tree->insert(a[i]); } cout<<"depth of 110 "<<tree->depth(110)<<endl; cout << "前序遍历: "; tree->preOrder(); cout << "\n中序遍历: "; tree->inOrder(); cout << "\n后序遍历: "; tree->postOrder(); cout << endl; // cout << "最小值: " << tree->minimum() << endl; // cout << "最大值: " << tree->maximum() << endl; cout << "树的详细信息: " << endl; tree->print(); tree->deleteLessThan(100); cout<<"\n=====After delete node less than 100========="; cout << "\n中序遍历: "; tree->inOrder(); cout << "\n"; tree->destroy(); RBTree<int>* tree1=new RBTree<int>(); for(i=0; i<ilen; i++) { tree1->insert(a[i]); } cout<<"\n=====After delete node larger than 200========="; cout << "\n中序遍历: "; tree1->deleteLargerThan(200); tree1->inOrder(); cout << "\n"; RBTree<int>* tree2=new RBTree<int>(); for(i=0; i<ilen; i++) { tree2->insert(a[i]); } cout<<"\n=====After delete node 100 - 200========="; cout << "\n中序遍历: "; tree2->deleteBetween(100,200); tree2->inOrder(); cout << "\n"; return 0; }print?函数感觉写的很好?。。。 (编辑:ASP站长网) |
相关内容
网友评论
推荐文章
热点阅读