-3

我有一个程序可以在 c# 中创建一个链表,如下所示:

class Point
{
    public string Name { get; set; }
    public List<Point> NextPoints { get; set; }

    public Point()
    {
        NextPoints = new List<Point>();
    }
}

这是具有名称和下一个点的点对象。

我用数据填充点列表,

List<Point> Points;

我在这里定义了一条线:

class DashedLine
{
    public Point X { get; set; }
    public Point Y { get; set; }

}

我需要一个递归函数来获取给定DashedLine的循环

这样我就传递了DashedLine对象,该函数返回一个构成循环的点列表。

请帮我做这个功能。

4

1 回答 1

0

考虑改变你的数据结构,可能是这样的:

class Program
{
    static void Main(string[] args)
    {
        DashedLine line = new DashedLine();
        line.Points.Add(new Point { X = 1, Y = 1 });
        line.Points.Add(new Point { X = 2, Y = 2 });
        line.Points.Add(new Point { X = 3, Y = 3 });
        line.Points.Add(new Point { X = 4, Y = 4 });

        foreach (Point p in line.Points)
        {
            Debug.WriteLine("Point {0}, {1}", p.X, p.Y);
        }
    }
}

class Point
{
    public int X { get; set; }
    public int Y { get; set; }
}

class DashedLine
{
    public List<Point> Points { get; set; }

    public DashedLine()
    {
        Points = new List<Point>();
    }
}

输出:

Point 1, 1
Point 2, 2
Point 3, 3
Point 4, 4
于 2013-02-19T13:49:53.250 回答