FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
F-Sharp/Algorithms/Sort/Heap_Sort.fs at main · TheAlgorithms/F-Sharp · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
TheAlgorithms
/
F-Sharp
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
64
Star
242
Code
Issues
0
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
F-Sharp
/
Algorithms
/
Sort
/
Heap_Sort.fs
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (25 loc) · 879 Bytes
Breadcrumbs
F-Sharp
/
Algorithms
/
Sort
/
Heap_Sort.fs
Copy path
File metadata and controls
30 lines (25 loc) · 879 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
namespace
Algorithms.Sort
module
HeapSort
=
let inline
swap
(
a
:
'T
[])
i j
=
let
temp
=
a
.[
i
]
a
.[
i
]
<-
a
.[
j
]
a
.[
j
]
<-
temp
let inline
sift
cmp
(
a
:
'T
[])
start count
=
let rec
loop
root child
=
if
root
*
2
+
1
<
count
then
let
p
=
child
<
count
-
1
&&
cmp a
.[
child
]
a
.[
child
+
1
]
<
0
let
child
=
if
p
then
child
+
1
else
child
if
cmp a
.[
root
]
a
.[
child
]
<
0
then
swap a root child
loop child
(
child
*
2
+
1
)
loop start
(
start
*
2
+
1
)
let inline
heapsort
cmp
(
a
:
'T
[])
=
let
n
=
a.Length
for
start
=
n
/
2
-
1
downto
0
do
sift cmp a start n
for
term
=
n
-
1
downto
1
do
swap a term
0
sift cmp a
0
term
Back
|
FazBrowse Home
|
New Git URL