sbwcwusi 发表于 2014-4-29 09:02:43

一小段代码问题,有详细注释。求修复和完善

template <typename T>class CTree// 对红黑树的封装,方便游戏中数据的访问;
{
public:
CTree( void* tree = NULL)
{
m_head = (_OBJ_NODE*)*(unsigned int**)((unsigned int)tree+20);//取出C++标准库map的头指针; debug下加20指向头结点的指针;
}
~CTree(void)
{
}
typedef struct _OBJ_NODE
{
struct _OBJ_NODE* pLChild;
struct _OBJ_NODE* pParent;
struct _OBJ_NODE* pRChild;
T Myval;
char color;
char isnil;
}NODE,*PNODE;
   
void Increment()//递增遍历
{
if ((it->pRChild).isnil)      
{//如果当前结点有右结点,更新当前结点为右结点.
   it = it->pRChild;
   while ( (it->pLChild).isnil)//当前结点有左结点时更新到左叶子结点。
    it = it->pLChild;
}
else
{//当前结点没有右结点。(有两种情况:1当前结点为父结点的左结点时直接返回父结点,2 ...)
   while ((((it->pParent).pRChild).isnil&&m_pCur == (it->pParent).pRChild)) //当前结点为父结点的右结点,返回最上层右结点;
    it = it->pParent;
   it = it->pParent ;   // 此时当前结点为左结点,直接返回父结点。
}
}
void operator++()
{
Increment();
}
PNODE begin()
{
return m_head->pLChild ;// 从左叶子出发,方便递增遍历。
}
PNODE end()
{
return m_head;
}
PNODE m_head;
PNODE it;   // 迭代指针      
};
代码有问题,求封装成vcmap接口方式;

sbwcwusi 发表于 2014-5-7 13:02:49

这几天修改的一下,已经成功运行了。(debug 下运行成功)其它 要修改便移。
求大神帮我封装成模版   。。。。。

sbwcwusi 发表于 2014-5-7 15:15:07

代码里有一句错了请改成 while (!cur->pParent->isnil &&cur == cur->pParent->pRChild)//当前结点为父右结点时

阔怀 发表于 2015-8-10 12:01:58

{:1_1:}
页: [1]
查看完整版本: 一小段代码问题,有详细注释。求修复和完善