ID:1730047
 
Keywords: and, dequeue, enqueue, pop, push
(See the best response by Akto.)
Is it possible? If so, how? I learned about it in class a few weeks ago to do it in C++ and wondered if it'd be possible to achieve in Byond.

What push and pop is, is you create a list. But when you create the list, every item you put into the list is stacked at the front of the list. The first one in is the last one out.

Imagine pushing bullets into a magazine.

Can this be accomplished in Byond code? I hope I am posting in the right section of the forums to ask this.

The following snippet of code is from Baystation12's Space Station 13 server. As you can see, it just adds and removes from the list() and does not push or pop.

http://pastebin.com/PWHUsc00
Best response
I think this would be Developer Help, but is this what you are looking for?

http://www.byond.com/forum/?post=1695978&hl=list
The example Akto posted works, though it's not particularly efficient or practical, since BYOND has no primitive stack-based data type available (though imho this is not a problem at all).

An interesting thing to note is that all of your code actually does quite a lot of PUSHing and POPing anyway after being compiled to BYOND bytecode, if de-compiled samples are any indication.
You can also basically just mess with a list, for a stack.

Stack
var/list/__store = new()

proc
push(var/E)
src.__store += E

pop()
var/E = null
if (src.__store.len > 0)
E = src.__store[src.__store.len]
src.__store.len--
return E


A stack is after all, a linear data structure (like a list) with specific retrieval ordering semantics for pop().