|
s11ss
银牌会员
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『楼 主』:
[原创]**********起泡排序***********
@echo off
setlocal enabledelayedexpansion
:::::::::::::::::::::::::::::::::::::::::Bubble 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 i=1
:q
set changed=False
set /a j=%nx%
:v
set /a k=%j%-1
if !n%k%! gtr !n%j%! (
set /a temporary=!n%k%!
set /a n%k%=!n%j%!
set /a n%j%=!temporary!
set changed=True
)
set /a j-=1
if %j% geq %i% (
if not %j% equ 1 (
goto :v
)
)
if %changed% equ False goto :p
set /a i+=1
if %i% lss %nx% goto :q
::::::::Deal With Numbers::::::::
::::::::Print The Result::::::::
:p
::set /a qi=%maxinc%+1
::set /a zhi=%nx%+%maxinc%
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-15
|
|
2007-9-15 20:55 |
|
|
1112yuhua
初级用户
积分 106
发帖 44
注册 2007-6-1
状态 离线
|
『第
2 楼』:
楼主,能不能给出详细点的解释啊?
|
|
2007-9-16 19:40 |
|
|
s11ss
银牌会员
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『第
3 楼』:
Quote: | Originally posted by 1112yuhua at 2007-9-16 07:40 PM:
楼主,能不能给出详细点的解释啊? |
|
起泡排序,就是每次扫描数组时把最轻的"气泡"(最小的数)浮上去,下次扫描时就在本次扫描的数的个数的基础上减少一个,即排除已扫描到的轻"气泡".达到轻在上,重在下的目的.算法是一边扫描,一边交换"气泡"的位置.
|
|
2007-9-16 19:58 |
|
|
csx163
初级用户
积分 97
发帖 45
注册 2007-1-31
状态 离线
|
|
2007-9-16 23:10 |
|
|
s11ss
银牌会员
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『第
5 楼』:
Quote: | Originally posted by csx163 at 2007-9-16 11:10 PM:
书上是叫冒泡排序法 |
|
有的书上就叫起泡排序.
|
|
2007-9-17 12:14 |
|
|
yovie
初级用户
积分 92
发帖 42
注册 2007-8-14 来自 重庆市巫山县
状态 离线
|
『第
6 楼』:
斑竹难道禁止我发言了?
|
拾人牙慧者! |
|
2007-9-17 13:18 |
|
|
tianya921
新手上路
积分 10
发帖 4
注册 2007-8-6
状态 离线
|
『第
7 楼』:
有意思,不错,学习了.................
|
|
2007-9-17 13:21 |
|
|
jmz573515
银牌会员
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
『第
8 楼』:
试着写了一个...
@echo off
setlocal enabledelayedexpansion
echo 请输入要排序的数(用逗号分开):
set /p s=
set h=0
for %%i in (!s!) do (
set /a h+=1
set n!h!=%%i
)
for /l %%a in (1,1,!h!) do (
call :label n%%a
)
for /l %%b in (1,1,!h!) do (
set /p=!n%%b! <nul
)
pause>nul
goto :eof
:label
for /l %%j in (1,1,!h!) do (
if !%1! gtr !n%%j! (
set m=!%1!
set %1=!n%%j!
set n%%j=!m!
)
)
goto :eof VBS版的
n=inputbox("请输入你要排序的数(用逗号分开):","提示","1,32,43,543,264,432,34,764,342,76543,54")
s=split(n,","):l=ubound(s):redim m(l)
for i=0 to l
for j=i to l
if ccur(s(i))<ccur(s(j)) then tmp=s(i):s(i)=s(j):s(j)=tmp
next
m(i)=s(i)
next
msgbox join(m,",")
|
|
2007-9-26 16:28 |
|
|