# 请教一下，关于VFP实现并归排序算法的问题。

fojiao8745 2018-05-23 01:16:13
RT，想请教一下关于VFP实现并归排序算法的问题。

``````LOCAL lnTemp,lnArrlen,lcarrNo,lcBubbletime,lcMergetime
lnArrlen = 5000
CLEAR
**Get Array
DIMENSION arr(lnArrlen)
FOR i = 1 TO lnArrlen
arr(i) = ROUND(rand()*lnArrlen*10,0)
ENDFOR
ACOPY(arr,originalArr)

**Bubble Sort
T1 = SECONDS()
FOR i = 1 TO lnArrlen
FOR j = i + 1 TO lnArrlen
IF arr(i) > arr(j)
lnTemp = arr(i)
arr(i) = arr(j)
arr(j) = lnTemp
ENDIF
ENDFOR
ENDFOR
T2 = SECONDS()
lcBubbletime = 'BubbleSort用时: '+ALLTRIM(STR(T2-T1,10,3))+'秒'

**Recovery
ACOPY(originalArr,arr)

**Merge Sort
T1 = SECONDS()
FOR i = 1 TO lnArrlen
lcarrNo = ALLTRIM(STR(i))
DIMENSION arr&lcarrNo(1)
arr&lcarrNo(1) = arr(i)
ENDFOR
DIMENSION arrNow(lnArrlen)
arrNow(1) = arr1(1)
FOR i = 1 TO lnArrlen - 1
lcarrNo = ALLTRIM(STR(i))
FOR j = 1 TO i
IF arrNow(j) > arr&lcarrNo(1)
AINS(arrNow,j)
arrNow(j) = arr&lcarrNo(1)
j = i + 1
ENDIF
ENDFOR
AINS(arrNow,j)
arrNow(j) = arr&lcarrNo(1)
ENDIF
ENDFOR
T2 = SECONDS()
lcMergetime = 'MergeSort用时: '+ALLTRIM(STR(T2-T1,10,3))+'秒'

**Result
MESSAGEBOX('共'+ALLTRIM(STR(lnArrlen))+'个数'+ CHR(13) +lcBubbletime + CHR(13) + lcMergetime,48,'Tip')``````

...全文
1156 3 打赏 收藏 转发到动态 举报

3 条回复

liups 2018-05-25
• 打赏
• 举报

fojiao8745 2018-05-25
• 打赏
• 举报

liups 2018-05-24
• 打赏
• 举报

2,717

• 近7日
• 近30日
• 至今