User Tools

Site Tools


This is an old revision of the document!


Stack

A stack is a collection data type where the primary operations are push which adds an element and pop which removes. It is a Last-In-First-Out (LIFO) data structure, the last element pushed must be the first one popped.

Array Based

An array implementation uses an simple array and items are added and removed from the end of the array. In a language without dynamic arrays, the stack would keep track of the number of items and the available space, when the stack runs out of space the array would be reallocated to provide more space. In Javascript the array data structure is dynamically resized and the stack implementation is very simple. Arrays in Javascript provide native push and pop functions, for this visualisation these are reimplemented.

Properties

  • $O(1)$ push
  • $O(1)$ pop
  • $O(n)$ space

λ Stack_array-based

stack.1405060321.txt.gz · Last modified: 2015/02/02 08:24 (external edit)