Queue/Definition: Difference between revisions
→{{header|AutoHotkey}}
No edit summary |
|||
Line 366:
=={{header|AutoHotkey}}==
push("qu", 2), push("qu", 4), push("qu", 6)
MsgBox %ErrorLevel% ; ErrorLevel = -1: popped too much▼
▲While !empty("st") ; Repeat until stack is not empty
▲ MsgBox % pop("st") ; Print popped values (4, 2)
▲MsgBox % pop("st") ; Empty
▲MsgBox %ErrorLevel% ; ErrorLevel = 1: popped too much
;---------------------------------------------------------------------------
push(
;---------------------------------------------------------------------------
global
%stack%%_% := x▼
Else
%queue% .= "|" x
}
pop(stack) { ; pop value from stack named "stack"▼
;---------------------------------------------------------------------------
▲ If (_ < 1)
;---------------------------------------------------------------------------
Return "", ErrorLevel := 1▼
global
Return %stack%%_%, %stack%0 := _-1▼
StringSplit, Array, %queue%, |
If (Array0 = 0) {
Return, ""
}
If (Array0 = 1)
%queue% := ""
Else
%queue% := SubStr(%queue%, InStr(%queue%, "|") + 1)
}
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
global
}
▲empty(stack) { ; check if stack named "stack" is empty
▲ Return %stack%0<1
▲}</lang>
=={{header|C}}==
|