source: trunk/Softwares/Common/src/c/func_hanoi.c @ 102

Last change on this file since 102 was 102, checked in by rosiere, 15 years ago

Previous commit with new files :P

  • Property svn:keywords set to Id
File size: 678 bytes
Line 
1#include "func_hanoi.h"
2
3int hanoi_recursif(char pic_depart, char pic_destination, char pic_transition, int nb_disques)
4{
5  unsigned int nb_move = 0;
6 
7  if (nb_disques == 1)
8    {
9      nb_move = 1;
10    }
11  else
12    {
13      //on modifie les positions des palets
14      nb_move += hanoi_recursif(pic_depart     , pic_transition  , pic_destination, nb_disques - 1);
15      nb_move += hanoi_recursif(pic_depart     , pic_destination , pic_transition , 1             );
16      nb_move += hanoi_recursif(pic_transition , pic_destination , pic_depart     , nb_disques - 1);
17    }
18  return nb_move;
19}
20
21int hanoi(int nb_disques)
22{
23  return(hanoi_recursif('1', '2', '3', nb_disques));
24}
Note: See TracBrowser for help on using the repository browser.