Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Ruby

Idiom #293 Create a stack

Create a new stack s, push an element x, then pop the element into the variable y.

s = []
s.push(x)
y = s.pop

Array can be used as stack
var s = [];
s.add(x);
var y = s.removeLast();

For simple push / pop you can use the native List in Dart. For implementing a "real" Stack see attribution URL below.

New implementation...
< >
programming-idioms.org