Example #1
0
void hanoi::shift(stack *A, stack *B) {
	int tmp = 0;
	if(A->return_top_value() == -1) {
		shift(B,A);
	}
	else {
		tmp = A->return_top();
		A->pop(); 
		B->push(tmp);
	}
}
Example #2
0
void hanoi::move_legal() {
	int tmp = 0;	
	switch (find_small()) {
		case 1 :
			if(B.return_top() < C.return_top() )
				shift(&B, &C);
			else if (B.return_top() > C.return_top() )
				shift(&C, &B);
			else {
				exit(1);
			}
			break;
		case 2 :
			if(A.return_top() < C.return_top() )
				shift(&A, &C);
			else if (A.return_top() > C.return_top()) 
				shift(&C,&A);
			else {
//				cout << A.return_top() << "\t" << C.return_top() << "\t" << C.return_top_value() << endl;
				exit(2);
			}
			break;
		case 3 :
			if(A.return_top() < B.return_top() )
				shift(&A, &B);
			else if (A.return_top() > B.return_top())
				shift(&B, &A);
			else {
				exit(3); 
			}
	 } 
}