Дописать метод вывода Ханойских башен - C#
Формулировка задачи:
Итак. имеется следующий код:
нужно дописать метод PrintTowers, но почему-то не получается, пробовал разные варианты, но не могу получить доступ к массивам tower. Выводить должен как на картинке во вложении. Бесконечные плюсы в карму за помощь
public class Hanoi
{
int size, moves;
int[] tower1, tower2, tower3;
int top1, top2, top3;
Random rnd = new Random();
public Hanoi(int size)
{
this.size = size;
tower1 = new int[size];
tower2 = new int[size];
tower3 = new int[size];
top1 = size; top2 = top3 = moves = 0;
}
public void Fill()
{
for (int i = 0; i < size; i++)
tower1[i] = size - i;
}
public void HanoiTowers()
{
HT(ref tower1, ref tower2, ref tower3, ref top1, ref top2, ref top3, size);
Console.WriteLine("\nВсего ходов 2^n -1 = {0}", moves);
}
/// <summary>
/// Перенос count колец с tower1 на tower2, соблюдая
/// правила и используя tower3. Свободные вершины
/// башен - top1, top2, top3
/// </summary>
///
void HT(ref int[] t1, ref int[] t2, ref int[] t3, ref int top1, ref int top2, ref int top3, int count)
{
if (count == 1) Move(ref t1, ref t2, ref top1, ref top2);
else
{
HT(ref t1, ref t3, ref t2, ref top1, ref top3, ref top2, count - 1);
Move(ref t1, ref t2, ref top1, ref top2);
HT(ref t3, ref t2, ref t1, ref top3, ref top2, ref top1, count - 1);
}
}//HT
void Move(ref int[] t1, ref int[] t2, ref int top1, ref int top2)
{
t2[top2] = t1[top1 - 1];
top1--; top2++; moves++;
//PrintTowers();
}//Move
public void TestHanoiTowers()
{
Hanoi han = new Hanoi(10);
Console.WriteLine("Ханойские башни");
han.Fill();
han.PrintTowers();
han.HanoiTowers();
han.PrintTowers();
}
}//HanoiРешение задачи: «Дописать метод вывода Ханойских башен»
textual
Листинг программы
void HT(ref int[] t1, ref int[] t2, ref int[] t3, ref int top1, ref int top2, ref int top3, int count)