Exemple #1
0
 public void MoveDisks(int n, Tower dest, Tower buffer)
 {
     if (n > 0)
     {
         MoveDisks(n - 1, buffer, dest);
         MoveTopTo(dest);
         buffer.MoveDisks(n - 1, dest, this);
     }
 }
Exemple #2
0
        public static void Run()
        {
            int n = 3;
            Tower[] towers = new Tower[n];
            for (int i = 0; i < 3; i++)
            {
                towers[i] = new Tower(i);
            }

            for (int i = n - 1; i >= 0; i--)
            {
                towers[0].Add(i);
            }
            towers[0].MoveDisks(n, towers[2], towers[1]);
        }
Exemple #3
0
 public void MoveTopTo(Tower t)
 {
     int top = disks.Pop();
     t.Add(top);
     Console.WriteLine("Move disk {0} from {1} to {2}", top, Index(), t.Index());
 }