Queue/Definition: Difference between revisions

Content added Content deleted
(→‎{{header|VBScript}}: Section added)
Line 4,349: Line 4,349:
empty_ = queue.Count = 0
empty_ = queue.Count = 0
End Function</lang>
End Function</lang>
=={{header|VBScript}}==
<lang vb>' Queue Definition - VBScript
Option Explicit
Dim queue, i, x
Set queue = CreateObject("System.Collections.ArrayList")
If Not empty_(queue) Then Wscript.Echo queue.Count
push queue, "Banana"
push queue, "Apple"
push queue, "Pear"
push queue, "Strawberry"
Wscript.Echo "Count=" & queue.Count
Wscript.Echo pull(queue) & " - Count=" & queue.Count '
Wscript.Echo "Head=" & queue.Item(0)
Wscript.Echo "Tail=" & queue.Item(queue.Count-1)
Wscript.Echo queue.IndexOf("Pear", 0)
For i=1 To queue.Count
Wscript.Echo join(queue.ToArray(), ", ")
x = pull(queue)
Next 'i

Sub push(q, what)
q.Add what
End Sub 'push
Function pull(q)
Dim what
If q.Count > 0 Then
what = q(0)
q.RemoveAt 0
Else
what = ""
End If
pull = what
End Function 'pull
Function empty_(q)
empty_ = q.Count = 0
End Function 'empty_
</lang>
{{out}}
<pre>
Count=4
Banana - Count=3
Head=Apple
Tail=Strawberry
1
Apple, Pear, Strawberry
Pear, Strawberry
Strawberry
</pre>


=={{header|Wart}}==
=={{header|Wart}}==
Wart defines queues as lists with a pointer to the last element saved for constant-time enqueuing:
Wart defines queues as lists with a pointer to the last element saved for constant-time enqueuing: