Reader small image

You're reading from  Swift Data Structure and Algorithms

Product typeBook
Published inNov 2016
Reading LevelIntermediate
PublisherPackt
ISBN-139781785884504
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Mario Eguiluz Alebicto
Mario Eguiluz Alebicto
author image
Mario Eguiluz Alebicto

Mario Eguiluz Alebicto is a software engineer with over 15 years of experience in development. He started developing software with Java, later switched to Objective-C when the first iPhone delighted the world, and now, he is working with Swift and involved in backend technologies. He loves to code, build exciting projects, and learn new languages and frameworks. Apart from software development, Mario loves to travel, learn new hobbies, practice sports, and considers himself a hardcore gamer, which he has been since he was a child.
Read more about Mario Eguiluz Alebicto

Right arrow

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 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...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Swift Data Structure and Algorithms
Published in: Nov 2016Publisher: PacktISBN-13: 9781785884504

Author (1)

author image
Mario Eguiluz Alebicto

Mario Eguiluz Alebicto is a software engineer with over 15 years of experience in development. He started developing software with Java, later switched to Objective-C when the first iPhone delighted the world, and now, he is working with Swift and involved in backend technologies. He loves to code, build exciting projects, and learn new languages and frameworks. Apart from software development, Mario loves to travel, learn new hobbies, practice sports, and considers himself a hardcore gamer, which he has been since he was a child.
Read more about Mario Eguiluz Alebicto