I'm trying to display the pegs of the Hanoi Towers recursive algorithm. I want each step to appear separately as such:

For example if the number of disks is 2

A: 2 1
B:

C:

Move disk 1 from A to B
A: 2
B: 1

C:

Move disk 2 from A to C
A:
B: 1

C: 2

Move disk 1 from B to C

A:
B:
C: 2 1

How can I display the pegs like this in c++?

Each peg is an array.
Load peg 1 with the disks

peg[0] = 1
peg[1] = 2
etc

Each time you move a disk you must take the last value in the array and place it in the first open location in the new array/peg

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.