Dim S1(L To R) As String Dim P1(L To R) As Long Dim L1(L To R) As Long For I = L To R S1(I) = GetRandomString() P1(I) = I L1(I) = GetRandomLong() Next I
pHeapSortS L, R, S1, P1 HeapSortL L, R, L1
Sub pHeapSortS(L As Long, R As Long, A() As String, P() As Long) Dim Node As Long Dim Last As Long Dim TMP As Long For Node = (R + L) \ 2 To L Step -1 pHeapS Node, L, R, A, P Next Node
For Last = R To L + 1 Step -1 TMP = P(L) P(L) = P(Last) P(Last) = TMP pHeapS L, L, Last - 1, A, P Next Last End Sub
Sub pHeapS(ByVal Node As Long, L As Long, R As Long, A() As String, P() As Long) Dim LEAF As Long Dim TMP As Long
Do LEAF = Node + Node - (L - 1) If LEAF > R Then Exit Sub If LEAF < R Then If A(P(LEAF + 1)) > A(P(LEAF)) Then LEAF = LEAF + 1 If A(P(Node)) > A(P(LEAF)) Then Exit Sub TMP = P(Node) P(Node) = P(LEAF) P(LEAF) = TMP Node = LEAF Loop End Sub
Sub HeapSortL(L As Long, R As Long, A() As Long) Dim Node As Long Dim Last As Long Dim TMP AS Long For Node = (R + L) \ 2 To L Step -1 HeapL Node, L, R, A Next Node For Last = R To L + 1 Step -1 TMP = A(L) A(L) = A(Last) A(Last) = TMP HeapL L, L, Last - 1, A Next Last End Sub
Sub HeapL(ByVal Node As Long, L As Long, R As Long, A() As Long) Dim LEAF As Long Dim TMP AS Long
Do LEAF = Node + Node - (L - 1) If LEAF > R Then Exit Sub If LEAF < R Then If A(LEAF + 1) > A(LEAF) Then LEAF = LEAF + 1 If A(Node) > A(LEAF) Then Exit Sub TMP = A(Node) A(Node) = A(LEAF) A(LEAF) = TMP Node = LEAF Loop End Sub |