Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions pairing-heap-csharp/PairingHeap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,39 +107,30 @@ private PairingNode<T> Link(PairingNode<T> node1, PairingNode<T> node2)

private PairingNode<T> Extract(PairingNode<T> node)
{
var children = new List<PairingNode<T>>();
if (node.Child is null)
return null;

PairingNode<T> result = null;

var n = node.Child;
while (!object.ReferenceEquals(n, null))
{
if (n.Sibling is null)
return Link(result, n);

var pair = n.Sibling;
n.Parent = null;
n.Sibling = null;
if (object.ReferenceEquals(pair, null))
{
children.Add(n);
break;
}

var next = pair.Sibling;
pair.Parent = null;
pair.Sibling = null;
children.Add(Link(n, pair));
n = next;
}
result = Link(result, Link(n, pair));

if (children.Count == 0)
{
return null;
}

var root = children[0];
for (var i = 1; i < children.Count; ++i)
{
root = Link(root, children[i]);
n = next;
}

return root;
return result;
}

public int Count
Expand Down