Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int start = aux[0];
- int goal = aux[1];
- if (n_dsks == 1)
- moves.push_back(VI { aux[0], aux[1] });
- else {
- int k = k_hanoi[n_twrs][n_dsks];
- // moves top k disks from start to sparing tower
- int sparing = aux[n_twrs-1];
- aux[1] = sparing;
- aux[n_twrs-1] = goal;
- hanoi(moves, n_twrs, k, aux);
- // moves bottom n-k disks from start to goal
- aux[0] = start;
- aux[1] = goal;
- hanoi(moves, n_twrs - 1, n_dsks - k, aux);
- // moves original k disks from sparing tower to goal
- aux[0] = sparing;
- aux[n_twrs-1] = start;
- hanoi(moves, n_twrs, k, aux);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement