Logo

Programming-Idioms

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

Idiom #293 Create a stack

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

const s = [1, 2, 3];
s.push(x);
const y = s.pop();

This is an array used as a 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