diff --git a/CPP/miscelanious/hanoi/hanoi.cpp b/CPP/miscelanious/hanoi/hanoi.cpp index f4879d4..61c24a8 100644 --- a/CPP/miscelanious/hanoi/hanoi.cpp +++ b/CPP/miscelanious/hanoi/hanoi.cpp @@ -99,7 +99,7 @@ void onlyLegalMove(std::deque &firstRod, std::deque &secondRod) } } -void doTheThingEven(std::deque &firstRod, std::deque &secondRod, std::deque &thirdRod) +void doTheThingEven(std::deque &firstRod, std::deque &secondRod, std::deque &thirdRod, const unsigned int numberOfPlates) { int i = 0; do{ @@ -109,14 +109,14 @@ void doTheThingEven(std::deque &firstRod, std::deque &secondRod, std:: i++; onlyLegalMove(secondRod, thirdRod); i++; - }while(thirdRod.size() != 6); + }while(thirdRod.size() != numberOfPlates); printDeque(firstRod); printDeque(secondRod); printDeque(thirdRod); std::cout << i << std::endl; } -void doTheThingOdd(std::deque &firstRod, std::deque &secondRod, std::deque &thirdRod) +void doTheThingOdd(std::deque &firstRod, std::deque &secondRod, std::deque &thirdRod, const unsigned int numberOfPlates) { int i = 0; do{ @@ -126,7 +126,7 @@ void doTheThingOdd(std::deque &firstRod, std::deque &secondRod, std::d i++; onlyLegalMove(secondRod, thirdRod); i++; - }while(thirdRod.size() != 6); + }while(thirdRod.size() != numberOfPlates); printDeque(firstRod); printDeque(secondRod); printDeque(thirdRod); @@ -140,17 +140,27 @@ odd: AC AB BC */ +std::deque fillDeque(const int maxNumber) +{ + std::deque deque; + for(int i = 1; i <= maxNumber; i++ ) + { + deque.push_back(i); + } + return deque; +} int main() { - //int numberOfPlates = 6; - + unsigned int numberOfPlates; + std::cout << "Enter number of plates: " << std::endl; + std::cin >> numberOfPlates; std::deque firstRod, secondRod, thirdRod; - firstRod = {1, 2, 3, 4, 5, 6}; + firstRod = fillDeque(numberOfPlates); secondRod = {}; thirdRod = {}; - if(firstRod.size() % 2 == 0) doTheThingEven(firstRod, secondRod, thirdRod); - else doTheThingOdd(firstRod, secondRod, thirdRod); + if(firstRod.size() % 2 == 0) doTheThingEven(firstRod, secondRod, thirdRod, numberOfPlates); + else doTheThingOdd(firstRod, secondRod, thirdRod, numberOfPlates); return 0;