recursive hanoi with 2D arrays

Hi, so upon searching for info it would seem there is rarely any replies when people ask about towers of hanoi code. But I'm going to ask anyways. I'm not asking for code really. I just need hints and advice on how to go about it given my requirements. And I suck at recursion so that doesn't help. But here it goes. We were given a snippet of pseudo-code and we have to figure out the rest. We have to use 2D arrays also and I haven't seen anyone one on the internet do it like that yet so I really have nothing to go off of quite yet.
Here's the code I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>


using namespace std;


/*
 *
 */
void towers(int disks, int b[][COLS], int from_col, int to_col, int spare)
{

	if ( disks >= 1 )
	{
	
		towers(disks-1, b, from_col, spare, to_col);
		move( b, from_col, to_col);
		print( b, rows );
		towers(disks-1, b, spare, to_col, from_col);
	
	}

}

/*
 *
 */
void move(int disks, int b[][COLS], int from_col, int to_col, int spare)
{

        /* How do I move them? Hints? */

}

/*
 *
 */
void print()
{



}

int main()
{

	

	return 0;

}


I can probably figure out what to do with the print and main functions but I have no idea how to move the disks around or what the 2D array is doing for me/how it works with the code. The towers() function is supposed to be perfect already. I f I could just get some hints on how to move the stuff around I'll be happy. In the meantime if I think I figured something out I'll probably be asking to see if I'm on the right track. Thank you in advance. :)
It looks like COLS is the number of columns - typically 3. b[x][c] is the value of the disk in column c at level x. So if you start out with 3 disks in column 0 and their diameters are 10, 20, and 30 then b[0][0] = 30, b[1][0] = 20, and b[1][0] = 10.

So b represents the disks on the columns.

Your prototype for move() is different from the way you use it in towers. It looks like the prototype should be:
void move (int b[][COL], int from_col, int to_col);

The code appears very simple to me. Just move the bottom disk from the "from_col" to the "to_col". Think about how b represents the disks to figure out how to do this. Some thoughts:
- The "from_column" should contain only 1 disk. You might want to check this (just check if there is a disk at level 2).
- At which level will the disk go in the "to column"? You'll have to see how high the "to column" is.
- Don't forget to zero out the position in the from_column to indicate that it's now empty.

Hi, ok so it looks like I'm more lost than I originally thought. Everything you said makes sense. But I'm still not sure how certain things are supposed to work.
I defined COLS = 3 since that must always remain constant. For b[][COLS], the empty [] should always make my columns as many spaces high as there are disks right? If so could i just do b[disks][COLS]? And then are the from_column and to_column just set equal to which ever disk they're getting/receiving? I probably have more questions but I'll leave it at that for the moment.
Thanks again. :)
No, b[][COL] just means that it's a 2D array and the 1st dimension isn't specified.
Topic archived. No new replies allowed.