问题标签 [red-black-tree-insertion]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
24 浏览

c - 为什么在我的红黑树中我有一个来自红色节点的红色孩子?

在我的红黑树中,我有来自红色节点的红色孩子,我的代码有什么问题?

RBTree 的结构:

函数用 T->Nil sentinel 创建一个 RBTree 并创建一个新节点:

现在用insertfixup、insertfixupleft和right、左右旋转的insert算法代码:

//leftRotate 相同,但左右颠倒

// 与 fixupleft 相同,但左右颠倒

现在通过 insert 在树中插入元素后,我意识到一些红色节点有时会有一个红色的孩子,不尊重红黑的有效性。我在我的代码中找不到错误,有人可以帮助我吗?