Balanced brackets: Difference between revisions
Content added Content deleted
m (→{{header|J}}: eliminate unneeded punctuation) |
Simple9371 (talk | contribs) (Changed method of balance checking...) |
||
Line 594: | Line 594: | ||
=={{header|Batch File}}== |
=={{header|Batch File}}== |
||
Uses a "Markov-like" algorithm <code>"[]"->null</code> to check if brackets are balanced. |
|||
<lang dos>:: Balanced Brackets Task from Rosetta Code Wiki |
<lang dos>:: Balanced Brackets Task from Rosetta Code Wiki |
||
:: Batch File Implementation |
:: Batch File Implementation |
||
Line 635: | Line 636: | ||
goto :EOF |
goto :EOF |
||
::/Generate strings of brackets. |
::/Generate strings of brackets. |
||
::Check for Balance... |
::Check for Balance... |
||
::Uses Markov Algorithm. |
|||
:checkforbalance |
:checkforbalance |
||
set |
set "changes=!samp!" |
||
:check_loop |
|||
set cyc=0 |
|||
⚫ | |||
:scanchars |
|||
⚫ | |||
set currchar=!samp:~%counter%,1! |
|||
if "!currchar!"=="" ( |
|||
set input=!changes! |
|||
set "changes=!input:[]=!" |
|||
for %%A in ("!prev!") do set prevchar=!samp:~%%A,1! |
|||
goto check_loop |
|||
⚫ | |||
goto :itsbal |
|||
) |
|||
if %cyc%==0 ( |
|||
⚫ | |||
set /a cyc+=1 |
|||
) else ( |
|||
if "!currchar!"=="[" (set /a cyc+=1) else (set /a cyc-=1) |
|||
) |
|||
set /a counter+=1&goto scanchars |
|||
:itsbal |
:itsbal |