Stack
A stack is a Last In First Out (LIFO) data structure. You can think of a LIFO structure resembling a stack of plates; the last plate added to the stack is the first one removed. A stack is similar to an array but provides a more limited, controlled method of access. Unlike an array, which provides random access to individual elements, a stack implements a restrictive interface that tightly controls how elements of a stack are accessed.
Stack data structure
A stack implements the following three methods:
push()
- Adds an element to the bottom of a stackpop()
- Removes and returns an element from the top of a stackpeek()
- Returns the top element ...
Get Swift Data Structure and Algorithms now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.