为了账号安全,请及时绑定邮箱和手机立即绑定

cmd.exe(批处理)脚本中的数组,链接列表和其他数据结构

cmd.exe(批处理)脚本中的数组,链接列表和其他数据结构

cmd.exe(批处理)脚本中的数组,链接列表和其他数据结构我正在玩cmd.exe,但在它的帮助下我没有找到任何信息,如何定义数组。我发现,如何定义简单变量:set a=10echo %a%但是,我想创建数组,链表等...那么,它能否在cmd.exe中使用(我的意思是:cmd.exe中是否存在任何数组关键字?)我想实现一些算法:泡泡排序快速排序侏儒排序等等...所以,我也想知道,Cmd.exe是否有引用或实例,结构等?导致其帮助不完整:/?可以通过图灵机定义将Cmd.exe定义为完整吗?(图灵完成)
查看完整描述

4 回答

?
FFIVE

TA贡献1797条经验 获得超6个赞

我刚才使用伪数组批量生成了冒泡排序。不确定为什么要使用它(虽然我会承认在另一个批处理文件中这样做),因为随着列表大小的增加它变得非常慢。更多的是为自己设置一个小挑战。 有人可能会觉得这很有用。


:: Bubblesort

:: Horribly inefficient for large lists

:: Dave Johnson implementation 05/04/2013

@echo off

setlocal enabledelayedexpansion

:: Number of entries to populate and sort

set maxvalue=50

:: Fill a list of vars with Random numbers and print them

for /l %%a in (1,1,%maxvalue%) do (

    set /a tosort%%a=!random!

)

:: echo them

set tosort

:: Commence bubble sort

Echo Sorting...

set /a maxvalue-=1

set iterations=0

for /l %%a in (%maxvalue%,-1,1) do ( REM Decrease by 1 the number of checks each time as the top value will always float to the end

    set hasswapped=0

        for /l %%b in (1,1,%%a) do (

            set /a next=%%b+1

            set next=tosort!next!

            set next=!next!

            call :grabvalues tosort%%b !next!

            rem echo comparing tosort%%b = !tosortvalue! and !next! = !nextvalue!

            if !nextvalue! LSS !tosortvalue! (

            rem set /a num_of_swaps+=1

            rem echo Swapping !num_of_swaps!

                set !next!=!tosortvalue!

                set tosort%%b=!nextvalue!

                set /a hasswapped+=1

            )

        )

    set /a iterations+=1

    if !hasswapped!==0 goto sorted

)

goto:eof

:grabvalues

set tosortvalue=!%1!

set nextvalue=!%2!

goto:eof

:sorted

::nice one our kid

set tosortvalue=

echo Iterations required: %iterations%

set tosort

endlocal


查看完整回答
反对 回复 2019-05-22
  • 4 回答
  • 0 关注
  • 2099 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信