Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Solve this program with C + + Problem statement: Towers of Hanoi is a simple puzzle that we're going to be using as practice for
Solve this program with C + +
Problem statement: Towers of Hanoi is a simple puzzle that we're going to be using as practice for recursion and 2D arrays. The puzzle itself is very simple- it consists of three columns arranged from left to right, and some number of disks N of different sizes. To begin, the N disks are placed on the 1st is to finish with the disks arranged in the same order (biggest on the bottom, smallest on the top) on the 2nd column. Of course, you can't just move the disks however you want! You need to follow these rules: You can only move one disk at a time by taking it off the top of its peg and putting it onto another peg. You're not allowed to place a disk on top of another disk that's smaller-that is, every disk must be smaller than every disk beneath it on the peg. Dynamically Allocated 2-D array (3 pts) Next, implement this is using a dynamically allocated 2-D array with 3 columns for the 3 posts and N rows for N disks. Get the number of disks from the user as a command-line argument, i.e. towers 5 Continue to initialize the array with the numbers corresponding to the disks in the first column and 0s in all other columns to represent the initial state of the game. You should now see the above example output, given 2 for the number of disks. Remember to change your towers() and print_array() function parameters to accept dynamically allocated arrays, rather than statically allocated. To help you out, your towers() function will be change to the following prototype: void towers(int number_of disks, int *b, int from_col, int to_col, int spare); Make sure you delete your board after calling the towers function. Create/Delete Functions for Dynamically Allocated 2-D array
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started