 
- 帖子
- 22
- 积分
- 284
- 技术
- 0
- 捐助
- 0
- 注册时间
- 2008-8-18
|
下午刚写了个快速排序,正好用上啦.冒泡就不写了.
cls&@echo off&setlocal enabledelayedexpansion
set "strings=3 2008 11 19 777 23 2014 453 789 51"
echo %strings%
set/a n=0
for %%i in (%strings%) do (
set/a n+=1
set num[!n!]=%%i
)
call :quicksort num 1 %n%
for /l %%i in (1,1,%n%) do echo !num[%%i]!
pause&goto:eof
:QuickSort
::code by dishuostec
::use call :quicksort arrary low high
set "ARR=%1"
set/a dep=0
call :QS %2 %3
goto:eof
:QS
set/a dep+=1,lTmpLow=%1,lTmpHi=%2,Low=%1,Hi=%2
if %Hi% leq %Low% set/a dep-=1&goto :eof
set/a lTmpMid=(Low+Hi)/2
call set/a vTempVal=%%%ARR%[!lTmpMid!]%%
:qsMainLoop
if !lTmpLow! leq !lTmpHi! (
:qsLoop1
call set/a vVal=%%%ARR%[!lTmpLow!]%%
if !vVal! lss !vTempVal! if !lTmpLow! lss !Hi! set/a lTmpLow+=1& goto qsLoop1
:qsLoop2
call set/a vVal=%%%ARR%[!lTmpHi!]%%
if !vTempVal! lss !vVal! if !Low! lss !lTmpHi! set/a lTmpHi-=1&goto qsLoop2
:qsSwap
if !lTmpLow! leq !lTmpHi! (
call set/a vTmpHold=%%%ARR%[!lTmpLow!]%%
call set/a %ARR%[!lTmpLow!]=%%%ARR%[!lTmpHi!]%%
set/a %ARR%[!lTmpHi!]=vTmpHold
set/a lTmpLow+=1,lTmpHi-=1
)
goto qsMainLoop
)
set/a lTmpLow[%dep%]=lTmpLow,Hi[%dep%]=Hi
if %Low% lss %lTmpHi% call :QS %Low% %lTmpHi%
call set lTmpLow=%%lTmpLow[!dep!]%%&call set Hi=%%Hi[!dep!]%%
if %lTmpLow% lss %Hi% call :QS %lTmpLow% %Hi%
set/a dep-=1&goto :eof |
-
1
评分人数
-
|