HI!!!!
I need some help on this program. I really don't know where I am...If I am very far for what I want or I am close, right now I am getting some error on the Solve function where I try to do this: Source.push_back(Destination.pop_back()); //Move from Source to Destination....................
The error says something about the function is declared void..like if I am trying to return something.....
If you have some hints for me or if you want to see how the output should look like, I have an executable file (for linux/unix system) that I can send to you. Right now I am programming it on Dev++ on Windows, later on I will paste it and everything on a linux system..Thanks for any help you can give to me
Code:
//Towers of Hanoi....
using namespace std;
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
void header(int &argc, int i);
void show(int &argc, vector<int> &array1, vector<int> &array2, vector<int> &array3);
void waitForUser();
void Solve(int N, vector<int> &Source, vector<int> &Aux, vector<int> &Destination);
void init(int argc, vector<int> &array1);
void swap(int &N, vector<int> &Source, vector<int> &Destination);
int main(int argc, char *argv[])
{
argc = 3;
int steps = pow(2,argc)-1;
vector<int> array1(argc);
vector<int> array2(argc);
vector<int> array3(argc);
for(int i = 0; i <= steps; i++){
header(argc, i);
init(argc, array1);
Solve(argc, array1, array2, array3);
show(argc, array1, array2, array3);
waitForUser();
//system("clear");
}
system("PAUSE");
return 0;
}
void header(int &argc, int i){
cout << "**** HANOI TOWER ****" << endl;
cout << "N=" << argc << setw(17) << "STEP " << i << endl;
}
void show(int &argc, vector<int> &array1, vector<int> &array2, vector<int> &array3){
for(int j = 0; j < argc; j++){
cout << setw(3) << array1[j] << setw(8) << array2[j] << setw(8) << array3[j] << endl;
}
cout << "===== ===== =====\n";
cout << " A B C\n\n";
}
void waitForUser() {
// waits for the user to hit <ENTER>
string dummy;
cout << "Press <ENTER>";
getline(cin, dummy);
cout << endl;
}
void Solve(int N, vector<int> &Source, vector<int> &Aux, vector<int> &Destination){
for(int i = 0; i < N; i++){
// while{N =! 0){
Solve(N-1, Source, Destination, Aux);
Source.push_back(Destination.pop_back()); //Move from Source to Destination
Solve(N-1, Aux, Source, Destination);
// }
}
}
void init(int argc, vector<int> &array1){
for(int j = 0; j < argc; j++)
array1[j] = j+1;
}
void swap(int &N, vector<int> &Source, vector<int> &Destination){
for(int i = 0; i < N; i++){
Destination[i] = Source[i];
//Source[i] = 0;
}
}