Solving problems using stacks

Stacks have a variety of applications in real-world problems. They can be used for backtracking problems to remember tasks or paths visited, and to undo actions (we will learn how to apply this example when we discuss graphs and backtracking problems later in this book). The Java and C# programming languages use stacks to store variables and method calls and there is a stack overflow exception that can be thrown, especially when working with recursive algorithms (which we will cover later in this book as well).

Now that we know how to use the Stack class, let's use it to solve some computer science problems. In this section, we will cover the decimal to binary problem, where we will also transform the algorithm ...

Get Learning JavaScript Data Structures and Algorithms - Third Edition 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.