There are only *two* broken commands in the array/stack/queue/list command set. All of the rest work fine.
Here are working examples of stacks and queues that I posted a little while back.
Stacks:
` Demonstration of the stack commands
`
` ADD TO stack - Adds a new item to the end of the array and
` sets the current index to point to that item.
` REMOVE FROM stack - Removes the first item at the front of the
` array sets the current index to point to the
` new front item.
` I use ArrayName() to access the current item (eg to set the values
` in the item just added to the stack, and to
` read the value at the top of the stack).
` Several things to note here:
` Adding to the stack automatically increases the size of the array.
` Removing from the stack automatically decreases the size of the
` array.
` You cannot create an empty array (at the moment - Lee may include
` it in Update 6) so the array needs to be cleared before you use
` it.
` No example of the 'array index to stack', because the current item
` is always pointing to the top of the stack either when adding
` or removing. This command may be required when switching between
` using and array/queue/list as a stack.
dim a() as integer
empty array a()
print "Add 5 items to the stack"
for i=1 to 5
n = rnd(1000)
print " Adding "; n; " to the stack"
add to stack a()
a() = n
next i
print
PrintStack()
print
print "Pop 2 items from the stack"
for i=1 to 2
print " Removing "; a(); " from the stack"
remove from stack a()
next i
print
PrintStack()
print
print "Add 5 more entries to the stack"
for i=0 to 4
n = rnd(1000)
print " Adding "; n; " to the stack"
add to stack a()
a() = n
next i
print
PrintStack()
print
print "Now remove items until the stack is empty"
while array index valid( a() )
print " Removing "; a(); " from the stack"
remove from stack a()
endwhile
print
PrintStack()
wait key
end
function PrintStack()
if array count( a() ) >= 0
print "The stack has "; array count( a() )+1; " items"
for i=0 to array count( a() )
print " Item "; i; " = "; a(i)
next i
else
print "The stack is empty"
endif
endfunction
Queues:
` Demonstration of the queue commands
`
` ADD TO QUEUE - Adds a new item to the end of the array and
` sets the current index to point to that item.
` REMOVE FROM QUEUE - Removes the first item at the front of the
` array sets the current index to point to the
` new front item.
` I use ArrayName() to access the current item (eg to set the values
` in the item just added to the queue).
` I use ArrayName(0) to access the front of the queue (eg to read the
` values prior to removing from the queue)
` - see below for the reason.
` Several things to note here:
` Adding to the queue automatically increases the size of the array.
` Removing from the queue automatically decreases the size of the
` array.
` You cannot create an empty array (at the moment - Lee may include
` it in Update 6) so the array needs to be cleared before you use
` it.
` No example of the 'array index to queue', because there is simply
` no need for this command (in my opinion).
` All it does is set the current index to the first item of the
` array, and you can get that value yourself by accessing array(0).
` Adding a new item to the queue resets the index to the last item
` in the array, and continually switching back to get the next
` value at the front of the queue is a pain.
dim a() as integer
empty array a()
print "Add 5 items to the queue"
for i=1 to 5
n = rnd(1000)
print " Adding "; n; " to the queue"
add to queue a()
a() = n
next i
print
PrintQueue()
print
print "Pop 2 items from the queue"
for i=1 to 2
print " Removing "; a(0); " from the queue"
remove from queue a()
next i
print
PrintQueue()
print
print "Add 5 more entries to the queue"
for i=0 to 4
n = rnd(1000)
print " Adding "; n; " to the queue"
add to queue a()
a() = n
next i
print
PrintQueue()
print
print "Now remove items until the queue is empty"
while array index valid( a() )
print " Removing "; a(0); " from the queue"
remove from queue a()
endwhile
print
PrintQueue()
wait key
end
function PrintQueue()
if array count( a() ) >= 0
print "The queue has "; array count( a() )+1; " items"
for i=0 to array count( a() )
print " Item "; i; " = "; a(i)
next i
else
print "The queue is empty"
endif
endfunction
For your information, the broken commands are ARRAY INSERT AT TOP (both versions) and ARRAY INSERT AT ELEMENT. This has been confirmed to me by Lee, who has also fixed these for Update 5.