Stacks are indexed collections which support very efficient O(1) addition
and removal from the front using unshift(v) and shift().
For familiarity, Stack also provides push(v), pop(), and peek(), but
be aware that they also operate on the front of the list, unlike List or
a JavaScript Array.
Note: reverse() or any inherent reverse traversal (reduceRight,
lastIndexOf, etc.) is not efficient with a Stack.
Stacks are indexed collections which support very efficient O(1) addition and removal from the front using
unshift(v)
andshift()
.For familiarity, Stack also provides
push(v)
,pop()
, andpeek()
, but be aware that they also operate on the front of the list, unlike List or a JavaScript Array.Note:
reverse()
or any inherent reverse traversal (reduceRight
,lastIndexOf
, etc.) is not efficient with a Stack.Stack is implemented with a Single-Linked List.