public static string printIntNode(IntNode chain) { string chainString = null; if (chain.next == null) { chainString += chain.ToString(); } else { chainString += chain.info + " ---> "; chainString += printIntNode(chain.next); } return(chainString); }
static void Main(string[] args) { Random rand = new Random(); int n = rand.Next(2, 100); IntNode chain = new IntNode(1); IntNode t = chain; for (int i = 2; i < n; i++) { t.next = new IntNode(i); t = t.next; } Console.WriteLine(IntNode.printIntNode(chain)); Console.ReadKey(); }
public IntNode(int x, IntNode next) { this.info = x; this.next = next; }
public IntNode(int x) { this.info = x; this.next = null; }