Fill in the blanks below. #include #include using namespace std; int main(){ vector t[3]; //

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Fill in the blanks below. #include #include using namespace std; int main(){ vector t[3]; //

Post by answerhappygod »

Fill in the blanks below.
#include <iostream>
#include<vector>
using namespace std;
int main(){
vector<int> t[3]; // three towers A,B,C
represented as an array of 3 vectors
int n, candidate,to, from, move=0; // move counts the
move number
cout<<"Please enter
an ODD number of rings to move: ";
cin>>n;
cout<<endl;

//intitialize the 3 towers
for(int i=n+1;i>=1;i--) t[0].push_back(i);
t[1].push_back(n+1);
t[2].push_back(n+1);
// initialize towers and candidate
from=0;
to=1;
candidate=1;
while( t[1].size()<n+1){ // there are still rings
to transfer to tower B = t[1]
cout<<"move number
"<<++move<<": Transfer ring " <<candidate<<
" from tower "
<<
char(from+65)<<" to
tower "<<char(to+65)<<endl;
//do it: move the disks around
t[to].
______________;
t[from].pop_back();

//get next “from tower” It’s not the
most recent “to” – so which is it?
if(_____________)
from = __________;
else
from = __________;

// get next “to tower”
if (___________)
to = ___________;
else
to = ___________;

//get next candidate
candidate = t[__________].back();
}
return 0;
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply