【发布时间】:2017-07-29 19:14:54
【问题描述】:
假设我在 C# 中有一个简单的链表。例如Creating a very simple linked list 其中任何一个。我想用三重嵌套的 for 循环遍历该列表。我可以展示一个包含我想要实现的数组的示例:
int[] a = new int[10];
//some code to place elements into that array
for(int i = 0; i<a.length; i++){
for(int q = i; q<a.length; q++){
for(int z = q; z<a.length; z++){
//do stuff with a[i], a[q], a[z], for example send them to a function
}
}
}
如果我有一个链表而不是数组,我该怎么做?假设我需要将所有这 3 个元素发送到一个函数。
提前感谢您的回答。
【问题讨论】:
-
实现一个
GetNthElement(LinedList, int)方法,该方法返回传递列表的第 N 个元素。