<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>https://acm.khpnets.info/w39/index.php?action=history&amp;feed=atom&amp;title=%D0%9A%D1%80%D0%B0%D1%81%D0%BD%D0%BE-%D1%87%D1%91%D1%80%D0%BD%D0%BE%D0%B5_%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BE</id>
	<title>Красно-чёрное дерево - История изменений</title>
	<link rel="self" type="application/atom+xml" href="https://acm.khpnets.info/w39/index.php?action=history&amp;feed=atom&amp;title=%D0%9A%D1%80%D0%B0%D1%81%D0%BD%D0%BE-%D1%87%D1%91%D1%80%D0%BD%D0%BE%D0%B5_%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BE"/>
	<link rel="alternate" type="text/html" href="https://acm.khpnets.info/w39/index.php?title=%D0%9A%D1%80%D0%B0%D1%81%D0%BD%D0%BE-%D1%87%D1%91%D1%80%D0%BD%D0%BE%D0%B5_%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BE&amp;action=history"/>
	<updated>2026-05-13T11:41:44Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://acm.khpnets.info/w39/index.php?title=%D0%9A%D1%80%D0%B0%D1%81%D0%BD%D0%BE-%D1%87%D1%91%D1%80%D0%BD%D0%BE%D0%B5_%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BE&amp;diff=2858&amp;oldid=prev</id>
		<title>Ctrlalt: /* Ссылки */</title>
		<link rel="alternate" type="text/html" href="https://acm.khpnets.info/w39/index.php?title=%D0%9A%D1%80%D0%B0%D1%81%D0%BD%D0%BE-%D1%87%D1%91%D1%80%D0%BD%D0%BE%D0%B5_%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BE&amp;diff=2858&amp;oldid=prev"/>
		<updated>2023-04-26T23:12:40Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Ссылки&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 23:12, 26 апреля 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l121&quot;&gt;Строка 121:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Строка 121:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Теория:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Теория:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:&lt;/del&gt;* [https://neerc.ifmo.ru/wiki/index.php?title=Красно-черное_дерево neerc.ifmo.ru/wiki — Красно-черное_дерево]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://neerc.ifmo.ru/wiki/index.php?title=Красно-черное_дерево neerc.ifmo.ru/wiki — Красно-черное_дерево]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:&lt;/del&gt;* [https://disk.yandex.ru/i/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;GtHnyXUHVF3arg &lt;/del&gt;Вставка в красно-чёрное дерево]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://disk.yandex.ru/i/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;7LKoFkz7vP7-8A &lt;/ins&gt;Вставка в красно-чёрное дерево]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:&lt;/del&gt;* [https://algs4.cs.princeton.edu/lectures/keynote/33BalancedSearchTrees.pdf algs4.cs.princeton.edu — Balanced Search Trees]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://algs4.cs.princeton.edu/lectures/keynote/33BalancedSearchTrees.pdf algs4.cs.princeton.edu — Balanced Search Trees]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Демонстрация:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Демонстрация:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:&lt;/del&gt;* [https://www.cs.usfca.edu/~galles/visualization/RedBlack.html www.cs.usfca.edu — Red/Black Tree]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://www.cs.usfca.edu/~galles/visualization/RedBlack.html www.cs.usfca.edu — Red/Black Tree]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Код:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Код:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:&lt;/del&gt;* [https://github.com/kevin-wayne/algs4/blob/master/src/main/java/edu/princeton/cs/algs4/RedBlackBST.java kevin-wayne/algs4/RedBlackBST.java]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://github.com/kevin-wayne/algs4/blob/master/src/main/java/edu/princeton/cs/algs4/RedBlackBST.java kevin-wayne/algs4/RedBlackBST.java]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ctrlalt</name></author>
	</entry>
	<entry>
		<id>https://acm.khpnets.info/w39/index.php?title=%D0%9A%D1%80%D0%B0%D1%81%D0%BD%D0%BE-%D1%87%D1%91%D1%80%D0%BD%D0%BE%D0%B5_%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BE&amp;diff=2673&amp;oldid=prev</id>
		<title>Ctrlalt: Новая страница: «== Правила == * Каждый узел является красным или чёрным. * Корень и (воображаемые) nullptr-потом...»</title>
		<link rel="alternate" type="text/html" href="https://acm.khpnets.info/w39/index.php?title=%D0%9A%D1%80%D0%B0%D1%81%D0%BD%D0%BE-%D1%87%D1%91%D1%80%D0%BD%D0%BE%D0%B5_%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BE&amp;diff=2673&amp;oldid=prev"/>
		<updated>2021-05-21T10:12:56Z</updated>

		<summary type="html">&lt;p&gt;Новая страница: «== Правила == * Каждый узел является красным или чёрным. * Корень и (воображаемые) nullptr-потом...»&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Правила ==&lt;br /&gt;
* Каждый узел является красным или чёрным.&lt;br /&gt;
* Корень и (воображаемые) nullptr-потомки листьев — чёрные.&lt;br /&gt;
* Родитель красного узла обязан быть чёрным (потомок и родитель не могут быть красными одновременно, не может быть двух красных узлов подряд);&lt;br /&gt;
* Все простые пути пути от любой вершины до любого листа в её поддереве содержат одинаковое количество чёрных узлов.&lt;br /&gt;
&lt;br /&gt;
== Код ==&lt;br /&gt;
 class RBTree {&lt;br /&gt;
     struct Node {&lt;br /&gt;
         int key;&lt;br /&gt;
         Node *l = nullptr, *r = nullptr, *p = nullptr;&lt;br /&gt;
         char color = &amp;#039;R&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
         Node *other(Node *n) {&lt;br /&gt;
             return l == n ? r : l;&lt;br /&gt;
         }&lt;br /&gt;
     } *root = nullptr;&lt;br /&gt;
 &lt;br /&gt;
     bool find(Node *node, int key) const {&lt;br /&gt;
         if (!node)&lt;br /&gt;
             return false;&lt;br /&gt;
         if (key == node-&amp;gt;key)&lt;br /&gt;
             return true;&lt;br /&gt;
         return find(key &amp;lt; node-&amp;gt;key ? node-&amp;gt;l : node-&amp;gt;r, key);&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     void rotateLeft(Node *x) {&lt;br /&gt;
         Node *y = x-&amp;gt;r;&lt;br /&gt;
         x-&amp;gt;r = y-&amp;gt;l;&lt;br /&gt;
         if (y-&amp;gt;l)&lt;br /&gt;
             y-&amp;gt;l-&amp;gt;p = x;&lt;br /&gt;
         y-&amp;gt;p = x-&amp;gt;p;&lt;br /&gt;
         if (!x-&amp;gt;p)&lt;br /&gt;
             root = y;&lt;br /&gt;
         else if (x == x-&amp;gt;p-&amp;gt;l)&lt;br /&gt;
             x-&amp;gt;p-&amp;gt;l = y;&lt;br /&gt;
         else&lt;br /&gt;
             x-&amp;gt;p-&amp;gt;r = y;&lt;br /&gt;
         y-&amp;gt;l = x;&lt;br /&gt;
         x-&amp;gt;p = y;&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     void rotateRight(Node *x) {&lt;br /&gt;
         Node *y = x-&amp;gt;l;&lt;br /&gt;
         x-&amp;gt;l = y-&amp;gt;r;&lt;br /&gt;
         if (y-&amp;gt;r)&lt;br /&gt;
             y-&amp;gt;r-&amp;gt;p = x;&lt;br /&gt;
         y-&amp;gt;p = x-&amp;gt;p;&lt;br /&gt;
         if (!x-&amp;gt;p)&lt;br /&gt;
             root = y;&lt;br /&gt;
         else if (x == x-&amp;gt;p-&amp;gt;r)&lt;br /&gt;
             x-&amp;gt;p-&amp;gt;r = y;&lt;br /&gt;
         else&lt;br /&gt;
             x-&amp;gt;p-&amp;gt;l = y;&lt;br /&gt;
         y-&amp;gt;r = x;&lt;br /&gt;
         x-&amp;gt;p = y;&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     void fix(Node *me) {&lt;br /&gt;
         if (me-&amp;gt;color == &amp;#039;B&amp;#039;)&lt;br /&gt;
             return;&lt;br /&gt;
 &lt;br /&gt;
         Node *dad = me-&amp;gt;p;&lt;br /&gt;
         if (dad &amp;amp;&amp;amp; dad-&amp;gt;color == &amp;#039;B&amp;#039;)&lt;br /&gt;
             return;&lt;br /&gt;
 &lt;br /&gt;
         Node *grandDad = dad-&amp;gt;p, *uncle = grandDad ? grandDad-&amp;gt;other(dad) : nullptr;&lt;br /&gt;
         if (uncle &amp;amp;&amp;amp; uncle-&amp;gt;color == &amp;#039;R&amp;#039;) {&lt;br /&gt;
             dad-&amp;gt;color = uncle-&amp;gt;color = &amp;#039;B&amp;#039;;&lt;br /&gt;
             grandDad-&amp;gt;color = &amp;#039;R&amp;#039;;&lt;br /&gt;
             return;&lt;br /&gt;
         }&lt;br /&gt;
 &lt;br /&gt;
         if (me == dad-&amp;gt;r &amp;amp;&amp;amp; dad == grandDad-&amp;gt;l) {&lt;br /&gt;
             rotateLeft(dad);&lt;br /&gt;
             return fix(me-&amp;gt;l);&lt;br /&gt;
         }&lt;br /&gt;
 &lt;br /&gt;
         if (me == dad-&amp;gt;l &amp;amp;&amp;amp; dad == grandDad-&amp;gt;r) {&lt;br /&gt;
             rotateRight(dad);&lt;br /&gt;
             return fix(me-&amp;gt;r);&lt;br /&gt;
         }&lt;br /&gt;
 &lt;br /&gt;
         dad-&amp;gt;color = &amp;#039;B&amp;#039;;&lt;br /&gt;
         grandDad-&amp;gt;color = &amp;#039;R&amp;#039;;&lt;br /&gt;
         if (me == dad-&amp;gt;l) {&lt;br /&gt;
             rotateRight(grandDad);&lt;br /&gt;
         } else {&lt;br /&gt;
             rotateLeft(grandDad);&lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     void insert(Node *&amp;amp;node, int key) {&lt;br /&gt;
         if (!node) {&lt;br /&gt;
             node = new Node({ key });&lt;br /&gt;
             return;&lt;br /&gt;
         }&lt;br /&gt;
         if (key &amp;lt; node-&amp;gt;key) {&lt;br /&gt;
             insert(node-&amp;gt;l, key);&lt;br /&gt;
             node-&amp;gt;l-&amp;gt;p = node;&lt;br /&gt;
             fix(node-&amp;gt;l);&lt;br /&gt;
         } else {&lt;br /&gt;
             insert(node-&amp;gt;r, key);&lt;br /&gt;
             node-&amp;gt;r-&amp;gt;p = node;&lt;br /&gt;
             fix(node-&amp;gt;r);&lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
 public:&lt;br /&gt;
     bool find(int key) const {&lt;br /&gt;
         return find(root, key);&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     void insert(int key) {&lt;br /&gt;
         insert(root, key);&lt;br /&gt;
         root-&amp;gt;color = &amp;#039;B&amp;#039;;&lt;br /&gt;
     }&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
== Ссылки ==&lt;br /&gt;
&lt;br /&gt;
Теория:&lt;br /&gt;
:* [https://neerc.ifmo.ru/wiki/index.php?title=Красно-черное_дерево neerc.ifmo.ru/wiki — Красно-черное_дерево]&lt;br /&gt;
:* [https://disk.yandex.ru/i/GtHnyXUHVF3arg Вставка в красно-чёрное дерево]&lt;br /&gt;
:* [https://algs4.cs.princeton.edu/lectures/keynote/33BalancedSearchTrees.pdf algs4.cs.princeton.edu — Balanced Search Trees]&lt;br /&gt;
Демонстрация:&lt;br /&gt;
:* [https://www.cs.usfca.edu/~galles/visualization/RedBlack.html www.cs.usfca.edu — Red/Black Tree]&lt;br /&gt;
Код:&lt;br /&gt;
:* [https://github.com/kevin-wayne/algs4/blob/master/src/main/java/edu/princeton/cs/algs4/RedBlackBST.java kevin-wayne/algs4/RedBlackBST.java]&lt;/div&gt;</summary>
		<author><name>Ctrlalt</name></author>
	</entry>
</feed>