#! /Usr/bin/perl-W <br/> use strict; <br/> Use 5.010; </P> <p> sub bigheapadjust ($ /@) {<br/> my ($ POs, $ Len, $ ARR) =@_; <br/> my $ temp = $ arr-> [$ POS]; <br/> # filter sons with large node values to the lower layer. 2 * r + 1 is the left son, 2 * (R + 1) yes right son <br/> for (my $ J = 2 * $ POS + 1; $ j <= $ len-1; $ J = 2 * $ J + 1) {<br/> $ J + + If $ j <$ len-1 & $ arr-> [$ J + 1] >=$ arr-> [$ J]; <br/> last if $ temp >=$ arr-> [$ J]; <br/> $ arr-> [$ POS] = $ arr-> [$ J]; <br/> $ Pos = $ J; <br/>}< br/> $ arr-> [$ POS] = $ temp; <br/>}< br/> sub bigheapsort ($ /@) {<br/> my ($ Len, $ ARR) =@_; <br/> for (my $ I = $ Len/2-1; $ I >= 0; $ I --) {<br/> bigheapadjust ($ I, $ Len, @ $ ARR ); <br/>}< br/> $ arr-> [0] ^ = $ arr-> [$ len-1]; <br/> $ arr-> [$ len-1] ^ = $ arr-> [0]; <br/> $ arr-> [0] ^ = $ arr-> [$ len-1]; <br/> # my $ temp = $ arr-> [0]; <br/> # $ arr-> [0] = $ arr-> [$ len-1]; <br/> # $ arr-> [$ len-1] = $ temp; </P> <p> for (my $ J = $ len-1; $ j> 1; $ j --) {<br/> bigheapadjust (0, $ J, @ $ ARR); <br/> $ arr-> [0] ^ = $ arr-> [$ J-1]; <br/> $ arr-> [$ J-1] ^ = $ arr-> [0]; <br/> $ arr-> [0] ^ = $ arr-> [$ J-1]; <br/> # $ temp = $ arr-> [0]; <br/> # $ arr-> [0] = $ arr-> [$ J-1]; <br/> # $ arr-> [$ J-1] = $ temp; <br/>}< br/> my @ arr = QW/13-54 87123 82344-23 3451 54-3 /; <br/> my $ n =$ # arr + 1; <br/> bigheapsort ($ N, @ ARR); <br/> say "@ arr ";