// lab7.cpp #include #include #include #include "lab7.h" using namespace std; //find which tower, towers[1] (B) or towers[2] (C), contains a given letter int locate_a_letter(char c, string towers[3]) { int i; for (i=0;i pos; i--) move(towers,t1,t2,fout); } //put 'f' into the bottom of tower A if it is not already there void achieve_first_letter(string towers[3],ofstream& fout) { if (towers[0].length() !=0 && towers[0][0]=='f') clear('f', 0, 1, towers, fout); //return if 'f' is already in the right position if (towers[0].length() != 0) //otherwise, clear tower A first { int j = towers[0].length(); for (int i=0; i pos && towers[0][pos] == c) return; //if it is already in the right position, then return //the rest is the same as in achieve_first_letter() int index = locate_a_letter(c,towers); //find out which tower has c int dump; //use to denote the other tower to clear c if (index == 1) dump = 2; else dump = 1; clear(c,index,dump,towers,fout); //make c clear first move(towers,index,0,fout); //move c to its destination - tower A }