vb6 使用指针来进行数组排序的问题
程序代码:
Public Declare Sub CopyMemory_Long Lib "kernel32" Alias "RtlMoveMemory" (Destination As Long, Source As Long, ByVal Length As Long) Public Function Arr_SelectSort(arr, Optional fs As Long = 1) '选择排序 Dim n, i, Min, J, temp If Not IsArray(arr) Then Exit Function n = UBound(arr) For i = 0 To n - 1 'Min = i CopyMemory_Long Min, i, 4 For J = Min + 1 To n If arr(Min) > arr(J) And fs = 1 Then 'Min = J CopyMemory_Long Min, J, 4 ElseIf arr(Min) < arr(J) And fs = 0 Then 'Min = J CopyMemory_Long Min, J, 4 End If Next CopyMemory_Long temp, arr(Min), 4 CopyMemory_Long arr(Min), arr(i), 4 CopyMemory_Long arr(i), temp, 4 ' temp = arr(Min) ' arr(Min) = arr(i) ' arr(i) = temp Next Arr_SelectSort = arr End Function
这段代码我在vb里面测试只有第一次能正确排序,第二次再测试程序就会没有响应,搞了几天看百度也没有找到结果,请懂指针操作的大神指点下