dataQ = { }
dataQ. first = 0
dataQ. last = - 1
dataQ. data = { }
function insert( q, val)
q. last = q. last + 1
q. data[ q. last] = val
end
function remove ( q)
if ( q. first > q. last) then
rval = - 1
else
print ( "remove: q.data[q.first]= " , q. data[ q. first] , " q.first= " , q. first)
local rval = q. data[ q. first]
print ( "remove: rval= " , rval)
q. data[ q. first] = nil -- to allow garbage collection
q. first = q. first + 1
print ( "remove: q.first= " , q. first)
end
return rval
end
insert( dataQ, "a" )
insert( dataQ, "b" )
insert( dataQ, "c" )
for i, v in ipairs ( dataQ. data) do
print ( i, v)
end
repeat
local x = remove ( dataQ)
print ( "list item= " , x)
until ( dataQ. first > dataQ. last)
-- your code goes here
ZGF0YVEgPSB7fQpkYXRhUS5maXJzdCA9IDAKZGF0YVEubGFzdCA9IC0xCmRhdGFRLmRhdGEgPSB7fQoKZnVuY3Rpb24gaW5zZXJ0KHEsIHZhbCkKICBxLmxhc3QgPSBxLmxhc3QgKyAxCiAgcS5kYXRhW3EubGFzdF0gPSB2YWwKZW5kCgpmdW5jdGlvbiByZW1vdmUocSkKICAgIGlmIChxLmZpcnN0ID4gcS5sYXN0KSB0aGVuIAogICAgICBydmFsID0gLTEKICAgIGVsc2UKICAgICAgcHJpbnQoInJlbW92ZTogcS5kYXRhW3EuZmlyc3RdPSAiLCBxLmRhdGFbcS5maXJzdF0sICIgIHEuZmlyc3Q9ICIsIHEuZmlyc3QpCiAgICAgIGxvY2FsIHJ2YWwgPSBxLmRhdGFbcS5maXJzdF0KICAgICAgcHJpbnQoInJlbW92ZTogcnZhbD0gIiwgcnZhbCkKICAgICAgcS5kYXRhW3EuZmlyc3RdID0gbmlsICAgICAgICAtLSB0byBhbGxvdyBnYXJiYWdlIGNvbGxlY3Rpb24KICAgICAgcS5maXJzdCA9IHEuZmlyc3QgKyAxCiAgICAgIHByaW50KCJyZW1vdmU6IHEuZmlyc3Q9ICIsIHEuZmlyc3QpCiAgICBlbmQKICAgIHJldHVybiBydmFsCmVuZAoKaW5zZXJ0KGRhdGFRLCJhIikKaW5zZXJ0KGRhdGFRLCJiIikKaW5zZXJ0KGRhdGFRLCJjIikKZm9yIGksdiBpbiBpcGFpcnMoZGF0YVEuZGF0YSkgZG8KICAgIHByaW50KGksIHYpCmVuZApyZXBlYXQKICAgIGxvY2FsIHggPSByZW1vdmUoZGF0YVEpCiAgICBwcmludCgibGlzdCBpdGVtPSAiLCB4KQp1bnRpbCAoZGF0YVEuZmlyc3QgPiBkYXRhUS5sYXN0KQoKLS0geW91ciBjb2RlIGdvZXMgaGVyZQ==