I'm having an issue with a Hanoi Tower problem. I'm passing an index variable and a vector to the recursive function. The disc numbers are being displayed correctly, but the peg numbers are not. The output is only the moves not the disc numbers on each peg.
Output should be Disc number 1 moved from peg 1 to peg 3. For the first move in a three peg and three disc run through. I've written a static version before, but the user defined variability is kinda throwing me through a loop.
My question is am I on the right track, and if so how can I get around the brick wall I keep running into? And yes, I may be at least somewhat retarded. :)
#include <iostream>
#include <vector>
using namespace std;
void moveDiscs(int, int, vector<int>);
int main()
{
int numDiscs;
int numPegs;
int index = 0;
//user input
cout << "Enter the number of discs to use: " << endl;
cin >> numDiscs;
cout << "Enter the number of pegs to use: " << endl;
cin >> numPegs;
//vector to hold peg information
vector<int> Pegs(numPegs);
//populate vector
Pegs[0] = numDiscs;
for(int i = 1; i <Pegs.size(); i++)
{
Pegs[i] = 0;
}
moveDiscs(numDiscs, index, Pegs);
cout << "All the discs are moved." << endl;
system("PAUSE");
return 0;
}
void moveDiscs(int num, int index, vector<int> pegs)
{
if(num > 0)
{
moveDiscs(num-1, index, pegs);
if(index < pegs.size())
++index;
if(index == pegs.size())
index = 0;
cout << "Move ring " << num << " from peg " << index
<< " to peg " << index + 1 << endl;
index++;
if(index == pegs.size())
index = 0;
moveDiscs(num-1, index, pegs);
}
}