Изменения

Перейти к: навигация, поиск

Биномиальная куча

287 байт добавлено, 23:23, 15 июня 2014
extractMin
<code>
'''Node ''' extractMin('''binomialHeap''' H) <font color = "green">//поиск корня х с минимальным значением ключа в списке корней Н:</font> min = <tex>\infty</tex> x = null xBefore = null curx = H.head curxBefore = null '''while ''' curx != null '''if''' curx.key < min <font color = "green"> // релаксируем текущий минимум if curx.key < min /font> min = curx.key x = curx xBefore = curxBefore curxBefore = curx curx = curx.sibling '''if''' (xBefore == null) <font color = "green"> //удаление найденного корня x из списка корней деревьев кучи</font> if (xBefore == null) H.head = x.sibling '''else ''' xBefore.sibling = x.sibling H' = null <font color = "green">//построение кучи детей вершины x, при этом изменяем предка соответствующего ребенка на null: H' = null</font>
curx = x.child
H'.head = x.child
'''while ''' curx != null p[curx] = null <font color = "green">// меняем указатель на родителя узла curx</font> p[ curx = curx] .sibling <font color = null "green">// переход к следующему ребенку</font> curx H = merge(H, H') <font color = curx.sibling "green">// слияние нашего дерева с деревом H'</font> H = merge(H, H') ''return ''' x
</code>
333
правки

Навигация