static void Main(string[] args) { Random rand = new Random(); ConcatStuLinkedList list1 = new ConcatStuLinkedList(); StuLinkedList list2 = new StuLinkedList(); int i, j; int[,] data = new int[12, 10]; String[] name1 = new String[] { "Allen", "Scott", "Marry", "Jon", "Mark", "Ricky", "Michael", "Tom" }; String[] name2 = new String[] { "Lisa", "Jasica", "Hanson", "Amy", "Bob", "Jack", "John", "Andy" }; WriteLine("座號 成績 座號 成績 座號 成績 座號 成績\n "); for (i = 0; i < 8; i++) { data[i, 0] = i + 1; data[i, 1] = (Math.Abs(rand.Next(50))) + 50; list1.Insert(data[i, 0], name1[i], data[i, 1]); } for (i = 0; i < 2; i++) { for (j = 0; j < 4; j++) { Write("[" + data[j + i * 4, 0] + "] [" + data[j + i * 4, 1] + "] "); } WriteLine(); } for (i = 0; i < 8; i++) { data[i, 0] = i + 9; data[i, 1] = (Math.Abs(rand.Next(50))) + 50; list2.Insert(data[i, 0], name2[i], data[i, 1]); } for (i = 0; i < 2; i++) { for (j = 0; j < 4; j++) { Write("[" + data[j + i * 4, 0] + "] [" + data[j + i * 4, 1] + "] "); } WriteLine(); } list1.Concat(list2); list1.Print(); ReadKey(); }
public StuLinkedList Concat(StuLinkedList stulist) { this.last.next = stulist.first; this.last = stulist.last; return(this); }