Book Image

Learning F# Functional Data Structures and Algorithms

By : Adnan Masood
Book Image

Learning F# Functional Data Structures and Algorithms

By: Adnan Masood

Overview of this book

Table of Contents (21 chapters)
Learning F# Functional Data Structures and Algorithms
Credits
Foreword
Foreword
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Let's build a stack


Stacks (also known as pushdown stacks) are simple, last-in-first-out data structures. The LIFO (Last-In-First-Out) policy of this data structure distinguishes it from the queues which follow the FIFO (First-In-First-Out) paradigm. A stack allows you to add and remove items by pushing and popping them off respectively. Some of the typical stack methods are as follows:

A typical modern day example of stack is a web browser where all the links are stored on a stack. When you press the back button (the metaphorical arch-nemesis of a web developer), it pops the last visited item in the sequence which is retrieved and so on and so forth. In this ordered collection of items, removals and the additions always occur from the same end point, that is, the top of the stack, contrary to the opposite end, the base. Therefore, by definition, the items closest to the base have been in the stack the longest.

As we saw in the last chapter, building an Abstract Data Type (ADT) requires us...