-
Book Overview & Buying
-
Table Of Contents
Swift Data Structure and Algorithms
By :
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 stack
pop() - Removes and returns an element from the top of a stack
peek() - Returns the top element from the stack, but does not remove it
Common implementations can also include helper operations such as the following:
count - Returns the number of elements in a stack
isEmpty() - Returns true if the stack is empty, and false otherwise
isFull() - If a stack limits the number of elements, this method will return true if it is full and false...