2013-02-19 65 views
-3

循環我有一個計劃,使在C#中的鏈表是這樣的:得到一個鏈表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對象,該函數返回一個禮st循環的點數。

請幫我做這個功能。

+2

您應該使用的所有對象的列表(在你的情況排序的一個最好),或一個鏈表(將下一個對象存儲在對象本身內)。混合起來聽起來像一個糟糕的主意 – Najzero 2013-02-19 13:45:11

+0

我只看到一些類。導致會徽的功能在哪裏? – 2013-02-19 13:46:20

+0

如果一個點有一個點列表,它不再是一個列表,它可以是樹或圖。 – R0MANARMY 2013-02-19 13:48:29

回答

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