扩大我之前的帖子,我仍然在写河内塔.在解释了如何在钉子上画出环之后,我有一个很好的解决方案,我仍然有一个问题,我现在已经摆弄了很长一段时间.
这是我的PegClass:
namespace Towers_Of_Hanoi
{
class PegClass
{
private int pegheight;
private int y = 3;
int[] rings = new int[0];
public PegClass()
{
//this is the default constructor
}
public PegClass(int height)
{
pegheight = height;
}
// other user defined functions
public void AddRing(int size)
{
Array.Resize (ref rings, rings.Length + 2);
rings[rings.Length - 1] = size;
}
public void DrawPeg(int x, int numberOfRings = 0)
{
for (int i = pegheight; i >= 1; i--)
{
string …Run Code Online (Sandbox Code Playgroud)