随笔 - 0  文章 - 5  trackbacks - 0
<2025年6月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用链接

留言簿(2)

文章分类

文章档案

教育

信息学奥赛

有用网站

在线OJ

专题测试

租房信息

搜索

  •  

最新评论


实现部分:
#include <iostream>
#include 
"SplayTree.h"
using namespace std;

static int arr[]= {10,50,40,30,20,60};
#define TBL_SIZE(a) ( (sizeof(a)) / (sizeof(a[0])) )

int main()
{
    
int i,ilen;
    SplayTree
<int>* tree=new SplayTree<int>();

    cout 
<< "== 依次添加: ";
    ilen 
= TBL_SIZE(arr);
    
for(i=0; i<ilen; i++)
    {
        cout 
<< arr[i] <<" ";
        tree
->insert(arr[i]);
    }

    cout 
<< "\n== 前序遍历: ";
    tree
->preOrder();

    cout 
<< "\n== 中序遍历: ";
    tree
->inOrder();

    cout 
<< "\n== 后序遍历: ";
    tree
->postOrder();
    cout 
<< endl;

    cout 
<< "== 最小值: " << tree->minimum() << endl;
    cout 
<< "== 最大值: " << tree->maximum() << endl;
    cout 
<< "== 树的详细信息: " << endl;
    tree
->print();

    i 
= 30;
    cout 
<< "\n== 旋转节点(" << i << ")为根节点";
    tree
->splay(i);
    cout 
<< "\n== 树的详细信息: " << endl;
    tree
->print();

    
// 销毁二叉树
    tree->destroy();
    
    
return 0;
}

posted on 2015-12-12 23:46 龙在江湖 阅读(143) 评论(0)  编辑 收藏 引用 所属分类: 算法