Jump to content

Sorting algorithms/Heapsort: Difference between revisions

Line 2,219:
=={{header|EasyLang}}==
 
<syntaxhighlight lang="text">subr make_heap
func sort . d[] .
for i = 1 to n - 1
n = len d[]
if data[i] > data[(i - 1) / 2]
# make heap
for i = 12 to n - 1
if datad[i] > datad[(i -+ 1) /div 2]
j = i
j = 0repeat
while data[j] > data[(j - 1) / 2]
swaph data[j]= data[(j -+ 1) /div 2]
until d[j] <= (j - 1) / 2d[h]
swap datad[0j] datad[ih]
ind j = 1h
.
.
.
for i = n - 1 downto 12
.
swap d[1] d[i]
subr sort
n = lenj = data[]1
ind = 2
call make_heap
for i = n - 1 downto 1
swap data[0] data[i]
j = 0
ind = 1
while ind < i
if ind + 1 < i and datad[ind + 1] > datad[ind]
ind += 1
.
if datad[j] < datad[ind]
swap datad[j] datad[ind]
.
j = ind
ind = 2 * j + 1
.
.
.
data[] = [ 29 4 72 44 55 26 27 77 92 5 ]
call sort data[]
print data[]</syntaxhighlight>
</syntaxhighlight>
 
=={{header|EchoLisp}}==
2,056

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.