O'Reilly logo

C# Data Structures and Algorithms by Marcin Jamro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example – Tower of Hanoi

The next example is a significantly more complex application of stacks. It is related to the mathematical game Tower of Hanoi. Let's start with the rules. The game requires three rods, onto which you can put discs. Each disc has a different size. At the beginning, all discs are placed on the first rod, forming the stack, ordered from the smallest (at the top) to the biggest (at the bottom), as follows:

The aim of the game is to move all the discs from the first rod (FROM) to the second one (TO). However, during the whole game, you cannot place a bigger disc on a smaller one. Moreover, you can only move one disc at ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required