Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Swift Data Structure and Algorithms

You're reading from   Swift Data Structure and Algorithms Implement Swift structures and algorithms natively

Arrow left icon
Product type Paperback
Published in Nov 2016
Publisher Packt
ISBN-13 9781785884504
Length 286 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Mario Eguiluz Alebicto Mario Eguiluz Alebicto
Author Profile Icon Mario Eguiluz Alebicto
Mario Eguiluz Alebicto
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Walking Across the Playground FREE CHAPTER 2. Working with Commonly Used Data Structures 3. Standing on the Shoulders of Giants 4. Sorting Algorithms 5. Seeing the Forest through the Tree 6. Advanced Searching Methods 7. Graph Algorithms 8. Performance and Algorithm Efficiency 9. Choosing the Perfect Algorithm

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 chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image