Fibonacci heap: Difference between revisions
Content deleted Content added
m →{{header|Phix}}: added syntax colouring, made p2js compatible |
Thundergnat (talk | contribs) m syntax highlighting fixup automation |
||
Line 16: | Line 16: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">template <class V> class FibonacciHeap; |
||
template <class V> struct node { |
template <class V> struct node { |
||
Line 322: | Line 322: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
A package. Implementation follows Fredman and Tarjan's 1987 paper. |
A package. Implementation follows Fredman and Tarjan's 1987 paper. |
||
< |
<syntaxhighlight lang="go">package fib |
||
import "fmt" |
import "fmt" |
||
Line 575: | Line 575: | ||
} |
} |
||
f(h.Node, "") |
f(h.Node, "") |
||
}</ |
}</syntaxhighlight> |
||
A demonstration: |
A demonstration: |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 628: | Line 628: | ||
h.Delete(x) |
h.Delete(x) |
||
h.Vis() |
h.Vis() |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 666: | Line 666: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="julia">module FibonacciHeaps |
||
export FNode, FibonacciHeap, insert, extractmin, findmin, decreasekey, delete! |
export FNode, FibonacciHeap, insert, extractmin, findmin, decreasekey, delete! |
||
Line 975: | Line 975: | ||
print(h3) |
print(h3) |
||
println("The minimum of h3 is now: ", Minimum(h3).value |
println("The minimum of h3 is now: ", Minimum(h3).value |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
Made heap 1: |
Made heap 1: |
||
Line 1,015: | Line 1,015: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="scala">// version 1.2.21 |
||
class Node<V : Comparable<V>>(var value: V) { |
class Node<V : Comparable<V>>(var value: V) { |
||
Line 1,283: | Line 1,283: | ||
h.delete(x) |
h.delete(x) |
||
h.visualize() |
h.visualize() |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,321: | Line 1,321: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Go & Kotlin}} |
{{trans|Go & Kotlin}} |
||
< |
<syntaxhighlight lang="nim">import strutils, tables |
||
type |
type |
||
Line 1,587: | Line 1,587: | ||
echo "(deleting $#)" % node.value |
echo "(deleting $#)" % node.value |
||
heap.delete(node) |
heap.delete(node) |
||
heap.visualize()</ |
heap.visualize()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,623: | Line 1,623: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">enum</span> <span style="color: #000000;">VALUE</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">PARENT</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">CHILD</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">PREV</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">NEXT</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">RANK</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">MARK</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">NODELEN</span><span style="color: #0000FF;">=$</span> |
<span style="color: #008080;">enum</span> <span style="color: #000000;">VALUE</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">PARENT</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">CHILD</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">PREV</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">NEXT</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">RANK</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">MARK</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">NODELEN</span><span style="color: #0000FF;">=$</span> |
||
Line 1,939: | Line 1,939: | ||
<span style="color: #000000;">h</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">Delete</span><span style="color: #0000FF;">(</span><span style="color: #000000;">h</span><span style="color: #0000FF;">,</span><span style="color: #000000;">x</span><span style="color: #0000FF;">)</span> |
<span style="color: #000000;">h</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">Delete</span><span style="color: #0000FF;">(</span><span style="color: #000000;">h</span><span style="color: #0000FF;">,</span><span style="color: #000000;">x</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #000000;">Vis</span><span style="color: #0000FF;">(</span><span style="color: #000000;">h</span><span style="color: #0000FF;">)</span> |
<span style="color: #000000;">Vis</span><span style="color: #0000FF;">(</span><span style="color: #000000;">h</span><span style="color: #0000FF;">)</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,975: | Line 1,975: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">class FibonacciHeap: |
||
# internal node class |
# internal node class |
||
Line 2,157: | Line 2,157: | ||
node.right.parent = parent |
node.right.parent = parent |
||
node.left.right = node.right |
node.left.right = node.right |
||
node.right.left = node.left</ |
node.right.left = node.left</syntaxhighlight> |
||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
{{trans|Go & Kotlin}} |
{{trans|Go & Kotlin}} |
||
<lang |
<syntaxhighlight lang="raku" line># 20200609 Raku programming solution |
||
subset vEle of Any; |
subset vEle of Any; |
||
Line 2,400: | Line 2,400: | ||
say "deleting: ", $x.value; |
say "deleting: ", $x.value; |
||
$h.Delete($x); |
$h.Delete($x); |
||
$h.Vis;</ |
$h.Vis;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>MakeHeap: |
<pre>MakeHeap: |
||
Line 2,437: | Line 2,437: | ||
{{libheader|Wren-str}} |
{{libheader|Wren-str}} |
||
This just deals with nodes whose values are strings. |
This just deals with nodes whose values are strings. |
||
< |
<syntaxhighlight lang="ecmascript">import "/str" for Str |
||
class Node { |
class Node { |
||
Line 2,720: | Line 2,720: | ||
System.print("(deleting '%(x.value)')") |
System.print("(deleting '%(x.value)')") |
||
h.delete(x) |
h.delete(x) |
||
h.visualize()</ |
h.visualize()</syntaxhighlight> |
||
{{out}} |
{{out}} |