在VC中使用STL的紅黑樹

最近考慮做個路由表,眾所周知這東西都是用Radix樹或者AVL樹(紅黑樹)造的。俺們是做工程的人,不搞學術,不打算研究這東西。

網上找了半天,終於有位兄弟告訴我們怎麼在VC的STL裡使用其自帶的紅黑樹(原文  http://woshao.com/article/7b4c844029c311dfa592000c295b2b8d/),good,來段例子。

 

#include "stdafx.h"
#include "windows.h"

#include <set>
#include <xtree>
#include <stdio.h>
 
using namespace std;
 
typedef _Tree<_Tset_traits<int, less<int>, allocator<int>, false>> RBTree;
 
int _tmain()
{
    RBTree * poTree = new RBTree(less<int>(), allocator<int>());
    for(int i = 35; i < 100; i++)
    {
        poTree->insert(i);
    }

    _tprintf(_T("output: %d\n"), *(poTree->begin()));


    return 0;
}


很爽吧。

還在研究當中。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值