标题: [原创] 常见几种排序的批处理写法 [打印本页]
作者: tyc 时间: 2009-4-17 10:01 标题: 常见几种排序的批处理写法
一、选择排序法- @echo off
- setlocal enabledelayedexpansion
- ::选择排序法
- echo 共输入10个数
- for /l %%i in (1,1,10) do (
- set /p a_%%i=请输入%%i个数
- set str=!str! !a_%%i!
- )
- echo %str%
- for /l %%i in (1,1,10) do (
- set /a b=%%i+1
- for /l %%j in (!b!,1,10) do (
- if !a_%%i! gtr !a_%%j! (
- set /a t=a_%%i
- set /a a_%%i=a_%%j
- set /a a_%%j=t
- )
- )
- )
- for /l %%i in (1,1,10) do (
- set str1=!str1! !a_%%i!
- )
- echo %str1%
- pause>nul
复制代码
二、冒泡排序法- ::冒泡排序法
- @echo off
- setlocal enabledelayedexpansion
- for /l %%i in (1,1,10) do (
- set /p a_%%i=请输入第%%i个数:
- set num=!num! !a_%%i!
- )
- echo %num%
- for /l %%i in (1,1,10) do (
- set /a b=10-%%i
- for /l %%j in (1,1,!b!) do (
- set /a t=%%j+1
- set /a d=a_!t!
- if !a_%%j! gtr !d! (
- set /a x=!a_%%j!
- set /a a_%%j=d
- set /a a_!t!=!x!
- )
- )
- )
- for /l %%i in (1,1,10) do (
- set str=!str! !a_%%i!
- )
- echo %str%
- pause>nul
复制代码
三、后序插入排序法- @echo off
- setlocal enabledelayedexpansion
- for /l %%i in (1,1,10) do (
- set /p a_%%i=请输入第%%i个数:
- set str=!str! !a_%%i!
- )
- echo 你输入的数列是: !str!
- for /l %%i in (1,1,10) do (
- rem set /a b=a_%%i
- rem echo !b!===
- set /a c=%%i+1
- for /l %%j in (!c!,1,10) do (
- if !a_%%j! lss !a_%%i! (
- set /a t=!a_%%j!
- set /a a_%%j=!a_%%i!
- set /a a_%%i=!t!
- )
- )
- )
- for /l %%i in (1,1,10) do set stri=!stri! !a_%%i!
- echo !stri!
- pause>nul
复制代码
四、后序插入排序优化- @echo off
- setlocal enabledelayedexpansion
- for /l %%i in (1,1,10) do (
- set /p a_%%i=请输入第%%i个数:
- set str=!str! !a_%%i!
- )
- echo 你输入的数列是: !str!
- for /l %%i in (1,1,10) do (
- set /a p=a_%%i
- set /a b=%%i+1
- for /l %%j in (!b!,1,10) do (
- if !a_%%j! lss !p! set /a p=a_%%j&set /a pp=%%j
- )
- set /a t=!a_%%i!
- set /a a_%%i=!p!
- set /a a_!pp!=!t!
- )
- for /l %%i in (1,1,10) do set stri=!stri! !a_%%i!
- echo !stri!
- pause>nul
复制代码
还要四种传统排序,以后再写
[ 本帖最后由 tyc 于 2009-4-17 10:03 编辑 ]
作者: Batcher 时间: 2009-4-17 12:44
不知楼主是原创还是转帖。如果是原创,当加分鼓励;如果是转帖,望注明出处。
直接插入排序
http://www.cn-dos.net/forum/viewthread.php?tid=33569- @echo off
- setlocal enabledelayedexpansion
-
- :::::::::::::::::::::::::::::::::::::::::Straight Insertion 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 num=%nx%+1
- set /a i=2
- :m
- set /a temporary=!n%i%!
- set /a j=%i%-1
- :j
- if %temporary% lss !n%j%! (goto :ch)
- goto :z
- :ch
- set /a k=%j%+1
- set /a n%k%=!n%j%!
- set /a j-=1
- if %j% gtr 0 goto :j
- :z
- set /a k=%j%+1
- set /a n%k%=%temporary%
- set /a i+=1
- if %i% lss %num% goto :m
- ::::::::Deal With Numbers::::::::
-
- ::::::::Print The Result::::::::
- for /l %%a in (1,1,%nx%) do (set str2=!str2!!n%%a! )
- 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-14
复制代码
希尔排序
http://www.cn-dos.net/forum/viewthread.php?tid=33578- @echo off
- setlocal enabledelayedexpansion
- :::::::::::::::::::::::::::::::::::::::::Shell 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 maxinc=(%nx%-1)/2
- set /a num=%nx%+1+%maxinc%
- for /l %%a in (%nx%,-1,1) do (set /a kk=%maxinc%+%%a & set /a n!kk!=!n%%a!)
- for /l %%b in (1,1,%maxinc%) do (
- (set /a n%%b=-214748320)
- )
- set /a var=1
- :n
- if %var% equ 1 (set /a m%var%=%maxinc%) else (set /a var2=%var%-1 & call :x)
- set /a i=!m%var%!+%maxinc%+1
- if !m%var%! equ 0 (goto :p) else (goto :m)
- :x
- set /a m%var%=!m%var2%!/2
- goto :eof
- :m
- set /a temporary=!n%i%!
- set /a j=%i%-!m%var%!
- :j
- if %temporary% lss !n%j%! (goto :ch)
- goto :z
- :ch
- set /a k=%j%+!m%var%!
- set /a n%k%=!n%j%!
- set /a j-=!m%var%!
- goto :j
- :z
- set /a k=%j%+!m%var%!
- set /a n%k%=%temporary%
- set /a i+=1
- if %i% lss %num% (goto :m) else (set /a var+=1 & goto :n)
- ::::::::Deal With Numbers::::::::
-
- ::::::::Print The Result::::::::
- :p
- set /a qi=%maxinc%+1
- set /a zhi=%nx%+%maxinc%
- for /l %%c in (%qi%,1,%zhi%) 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
复制代码
快速排序
http://www.cn-dos.net/forum/viewthread.php?tid=33602- @echo off
- setlocal enabledelayedexpansion
-
- :::::::::::::::::::::::::::::::::::::::::Quick 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
- call :oo 1 %nx%
- goto :p
- :oo
- set /a aa=%1
- set /a bb=%2
- if %aa% lss %bb% (
- call :partition %aa% %bb%
- set /a jj=!i!-1
- call :oo %aa% !jj!
- set /a ii=!i!+1
- call :oo !ii! %bb%
- )
- goto :eof
- :partition
- set /a i=%1
- set /a j=%2
- set /a temporary=!n%i%!
- :cir
- :cr2l
- if %temporary% leq !n%j%! (
- if %i% lss %j% (set /a j-=1 && goto :cr2l)
- )
- if %i% lss %j% (set /a n%i%=!n%j%! & set /a i+=1)
- :cl2r
- if %temporary% geq !n%i%! (
- if %i% lss %j% (set /a i+=1 && goto :cl2r)
- )
- if %i% lss %j% (set /a n%j%=!n%i%! & set /a j-=1)
- if not %i% equ %j% goto :cir
- set /a n%i%=%temporary%
- 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
复制代码
直接选择排序
http://www.cn-dos.net/forum/viewthread.php?tid=33609- @echo off
- setlocal enabledelayedexpansion
-
- :::::::::::::::::::::::::::::::::::::::::Straight Selection 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
- :ooo
- set /a k=%i%
- set /a j=%i%+1
- :oo
- if !n%j%! lss !n%k%! set /a k=%j%
- set /a j+=1
- if %j% leq %nx% goto :oo
- if %k% neq %i% (
- set /a temporary=!n%i%!
- set /a n%i%=!n%k%!
- set /a n%k%=!temporary!
- )
- set /a i+=1
- if %i% lss %nx% goto :ooo
- ::::::::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
复制代码
堆排序
http://www.cn-dos.net/forum/viewthread.php?tid=33623- @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
复制代码
起泡排序
http://www.cn-dos.net/forum/viewthread.php?tid=33595- @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
复制代码
VBS版各种排序
http://www.cn-dos.net/forum/viewthread.php?tid=34530- '''''''' 排序 ''''''''
- ''''''''s11ss 2007-10-18''''''''
-
- option explicit
- '接收输入:
- dim s,r,n,i
- s=inputbox(vbcrlf&vbcrlf&"以空格隔开:","请输入一组数:","2007 10 18 21 15")
- if s="" then wscript.quit
- r=split(s," ")
- n=ubound(r)
- '把字符串转换为Double 子类型:
- for i=0 to n
- r(i)=cdbl(r(i))
- next
-
- '快速排序方法调用:
- quicksort r,0,n
- '其它排序方法的调用:
- 'insertsort r
- 'shellsort r
- 'bubblesort r
- 'selectsort r
- 'heapsort r
-
- '输出结果:
- inputbox vbcrlf&vbcrlf&"按升序排列是:","结果",join(r," ")
-
-
-
-
-
-
-
-
- '各种排序子过程自定义:
- '直接插入排序:
- sub insertsort(r)
- dim i,n,t,j
- n=ubound(r)
- for i=1 to n'依次插入r(1),r(2),...,r(n)
- t=r(i)
- j=i-1
- do while t<r(j)'查找r(i)的插入位置
- r(j+1)=r(j)'将大于r(i)的数后移
- j=j-1
- if j=-1 then exit do
- loop
- r(j+1)=t'插入r(i)
- next
- end sub
-
- '希尔排序:
- sub shellsort(r)
- '设置增量序列:
- dim i,d(),n,t,k,h,j
- n=ubound(r)
- i=0
- redim d(n)
- d(i)=fix(n/2)
- do until d(i)=1
- t=d(i)
- i=i+1
- d(i)=fix(t/2)
- loop
- '排序:
- k=0
- do
- h=d(k)'取本趟增量
- for i=h to n'r(h)到r(n)插入当前有序区
- t=r(i)'保存待插入数
- j=i-h
- do while t<r(j)'查找正确的插入位置
- r(j+h)=r(j)'后移
- j=j-h'得到前一数的位置
- if j<0 then exit do
- loop
- r(j+h)=t'插入r(i)
- next'本趟排序完成
- k=k+1
- loop while h<>1
- end sub
-
- '冒泡排序:
- sub bubblesort(r)
- dim i,n,noswap,j,t
- n=ubound(r)
- for i=0 to n-1'做n趟排序
- noswap=True'置未交换标志
- for j=n-1 to i step -1'从下往上扫描
- if r(j+1)<r(j) then'交换
- t=r(j)
- r(j)=r(j+1)
- r(j+1)=t
- noswap=False
- end if
- next
- if noswap then exit for'本趟排序中未发生交换则终止算法
- next
- end sub
-
- '快速排序:
- '划分:
- function partition(r,l,h)
- dim i,j,t
- i=l
- j=h
- t=r(i)'初始化,t为基准
- do
- while r(j)>=t and i<j
- j=j-1'从右向左扫描,查找第1个小于t的数
- wend
- if i<j then
- r(i)=r(j)'交换r(i)和r(j)
- i=i+1
- end if
- while r(i)<=t and i<j
- i=i+1'从左向右扫描,查找第1个大于t的数
- wend
- if i<j then
- r(j)=r(i)'交换r(i)和r(j)
- j=j-1
- end if
- loop while i<>j
- r(i)=t'基准t已被最后定位
- partition=i
- end function
- '排序:
- sub quicksort(r,s1,t1)
- dim i
- if s1<t1 then'只有一个数或无数时无须排序
- i=partition(r,s1,t1)'对r(s1)到r(t1)做划分
- quicksort r,s1,i-1'递归处理左区间
- quicksort r,i+1,t1'递归处理右区间
- end if
- end sub
-
- '直接选择排序:
- sub selectsort(r)
- dim i,n,k,j,t
- n=ubound(r)
- for i=0 to n-1'做n趟排序
- k=i
- for j=i+1 to n'在当前无序区选最小的数r(k)
- if r(j)<r(k) then k=j
- next
- if k<>i then
- t=r(i)
- r(i)=r(k)
- r(k)=t
- end if
- next
- end sub
-
- '堆排序:
- '筛选:
- sub sift(r,i,m)'以r(i)为根的完全二叉树构成堆
- dim t,j
- t=r(i)
- j=2*i
- do while j<=m'j<=m,r(2*i)是r(i)的左孩子
- if j<m then
- if r(j)<r(j+1) then j=j+1'j指向r(i)的右孩子
- end if
- if t<r(j) then'孩子节点的数较大
- r(i)=r(j)'将r(j)换到双亲位置上
- i=j'修改当前被调整节点
- j=2*i
- else
- exit do'调整完毕,退出循环
- end if
- loop
- r(i)=t'最初被调整节点放入正确位置
- end sub
- '排序:
- sub heapsort(r)
- dim i,n,t
- n=ubound(r)
- for i=fix(n/2) to 0 step -1'建初始堆
- sift r,i,n
- next
- for i=n to 0 step -1'进行n+1趟排序
- t=r(0)'当前堆顶数和最后一个数交换
- r(0)=r(i)
- r(i)=t
- sift r,0,i-1'r(0)到r(i-1)重建成堆
- next
- end sub
复制代码
作者: tyc 时间: 2009-4-17 15:42 标题: re batcher
我不屑抄别人的代码。。。。。。。。。。。。。
小学生信息学竞赛必须掌握前三种,后四种是中学生要掌握的
象杨辉三角,约瑟夫问题等是小学生掌握的
n阶魔阵问题是初中生要掌握的
你们版主觉的很历害,其实优秀的初中生,如defansive这样的就会做的
但是中学生的题目我很多是做不出来的
[ 本帖最后由 tyc 于 2009-4-17 15:51 编辑 ]
作者: tyc 时间: 2009-4-17 15:58 标题: rebatcher
你动不动就封人家贴子,动不动就说抄人家的,所以你该被很多人骂!知道为什么?因为你伤人自尊,打击别人的学习积极性!
[ 本帖最后由 tyc 于 2009-4-17 16:27 编辑 ]
作者: Batcher 时间: 2009-4-17 16:07 标题: 回复 5楼 的帖子
2楼说的很明确,正是因为不知道真实情况,才分了两种情况询问的。
请问哪句话打击了你的积极性?你认为论坛管理人员在想表达2楼那句话的时候应该采取何种措施才能不打击你的积极性呢?
关于说我“动不动就封人家贴子”,请问你认为我封哪个帖子违反了本论坛的规定?请向管理员投诉,相信管理员能够秉公执法。如果没有真凭实据,我将投诉你污蔑他人。
作者: Batcher 时间: 2009-4-17 16:11 标题: 回复 4楼 的帖子
那就说明是原创了,非常感谢分享了。
哦对了,我不是版主。至于版主们是否认为会排序算法的人就算“很历害”,我也不敢妄自揣测。就我个人而言,小学生、初中生能够掌握这些排序算法,我感到非常钦佩并自叹佛如。
作者: 随风 时间: 2009-4-17 16:17
不知楼主是原创还是转帖。如果是原创,当加分鼓励;如果是转帖,望注明出处。
这句话看不出有伤人自尊,打击别人的学习积极性的地方啊。
tyc 会员看来对batcher成见很深啊,但在论坛发表
你动不动就封人家贴子,动不动就说抄人家的,所以你该被很多人骂!知道为什么?因为你伤人自尊,打击别人的学习积极性!
这样的言论不太合适吧。
关于用批处理数字排序,各大论坛多年前以有很多人讨论过,相关代码早以产生。
而本论坛向来尊重原创,所以作为管理员对该主题进行提醒应该是职责内的事
至于你说的小学生、中学生该掌握的,似乎和批处理没有必然联系吧?
batcher对你的提醒并不是因为你的代码技术含量低,而是因为该类代码以出现太多。
就我个人而言,小学生、初中生能够掌握这些排序算法,我也是非常感到非常钦佩并自叹佛如。
[ 本帖最后由 随风 于 2009-4-17 16:19 编辑 ]
作者: sjzong 时间: 2009-4-20 21:33
哦!还有这么多种排序!!学习
作者: 小勇12 时间: 2009-4-20 21:56
真牛。
哈哈
基数排序总不能用批处理写了啥
作者: wc726842270 时间: 2011-2-23 15:44
经典,可惜仅用VBS写过冒泡排序,学习了
作者: wslqy 时间: 2011-3-20 13:28
楼主辛苦了,学习学习下先
作者: 2010sftv 时间: 2011-3-20 18:31
进来学习一下算法。
作者: wangqi0077 时间: 2011-5-22 16:44
这些个东西,,能不能详细分开了讲讲原理等东西,,,新手表示,完全不知道是什么.
作者: chris521crystal 时间: 2011-6-1 18:38
@echo off
setlocal enabledelayedexpansion
::选择排序法
echo 共输入10个数
for /l %%i in (1,1,10) do (
set /p a_%%i=请输入%%i个数
set str=!str! !a_%%i!
)
echo %str%
for /l %%i in (1,1,10) do (
set /a b=%%i+1
for /l %%j in (!b!,1,10) do (
if !a_%%i! gtr !a_%%j! (
set /a t=a_%%i
set /a a_%%i=a_%%j
set /a a_%%j=t
)
)
)
for /l %%i in (1,1,10) do (
set str1=!str1! !a_%%i!
)
echo %str1%
pause>nul
请问这行“set str=!str! !a_%%i!”命令中的“!str! !a_%%i!”
是什么意思啊 ?为什么有2个变量没用其他运算符,而是空格
作者: plp626 时间: 2012-3-23 13:30
- @echo off|| 希尔排序练习
- setlocal enabledelayedexpansion
- ::获得256个随机数
- set n=255&for /l %%a in (0 1 !n!)do set/a a[%%a]=!random!
-
- ::获取制表符
- for /f "delims=U" %%a in ('cmd/u/cecho 唉')do set tab=%%a
-
- set x=0
- for /l %%a in (0 1 %n%)do (
- set/p=!a[%%a]!!tab!<nul&set/a x+=1,y=x%%8&if !y!==0 echo;
- )
- echo;---------------
-
- call:shellsort a n
-
- set x=0
- for /l %%a in (0 1 %n%)do (
- set/p=!a[%%a]!!tab!<nul&set/a x+=1,y=x%%8&if !y!==0 echo;
- )
- pause
-
- :shellsort <arrname> <arrsize> // code by plp
- for %%a in (132 57 23 9 4 1)do (
- for /l %%b in (%%a 1 !%2!)do (set/a x=%%b-%%a
- for /l %%c in (!x! -%%a 0)do (set/a jj=%%c+%%a
- for /f "tokens=1-2" %%A in ("a[%%c] a[!jj!] ")do (
- if !%%A! gtr !%%B! set/ap=%1[%%c],%1[%%c]=%1[!jj!],%1[!jj!]=p
- )
- )
- )
- )
- goto:eof
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |