亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 2244 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號