📄 堆排序.txt
字号:
@echo off
setlocal enabledelayedexpansion
:::::::::::::::::::::::::::::::::::::::::Heap Sort:::::::::::::::::::::::::::::::::::::::::
::::::::Get Original Numbers::::::::
echo Please input some numbers separated from "," , like 2007,9,14,88:
set /a s=0
set /p str=
set /a len=0
set /a nx=0
:c
call set word=%%str:~%len%,1%%
set /a len+=1
if "%word%" equ "," (set /a nx+=1 & call :e)
if not "%word%" equ "" (goto :c)
set /a nx+=1
call :e
goto :o
:e
set /a sn=%len%-%s%-1
call set n%nx%=%%str:~%s%,%sn%%%
set /a s=%len%
goto :eof
::::::::Get Original Numbers::::::::
::::::::Deal With Numbers::::::::
:o
set /a iv=%nx%/2
:v
call :sift %iv% %nx%
set /a iv-=1
if %iv% geq 1 goto :v
set /a iv=%nx%
:b
set /a tmpr=!n1!
set /a n1=!n%iv%!
set /a n%iv%=%tmpr%
set /a iii=%iv%-1
call :sift 1 %iii%
set /a iv-=1
if %iv% geq 2 goto :b
goto :p
:sift
set /a i=%1
set /a ww=%2
:oo
set /a t=!n%i%!
set /a j=2*%i%
:ooo
if not %j% leq %ww% goto :eof
if %j% lss %ww% (
set /a k=%j%+1
if !n%j%! lss !n%k%! (set /a j+=1)
)
if !t! lss !n%j%! (
set /a n%i%=!n%j%!
set /a i=%j%
set /a j=2*!i!
) else (goto :oooo)
set /a n%i%=%t%
if %j% leq %ww% goto :ooo
goto :eof
:oooo
set /a n!i!=%t%
goto :eof
::::::::Deal With Numbers::::::::
::::::::Print The Result::::::::
:p
for /l %%c in (1,1,%nx%) do (set str2=!str2!!n%%c! )
echo.
echo The numbers after sorting are:
echo !str2!
echo.
echo Press Any Key To Exit...
pause>nul
goto :eof
::::::::Print The Result::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::s11ss
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::2007-9-16
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -