Singly-linked list/Traversal: Difference between revisions
Content added Content deleted
(Added Dyalect programming language) |
(→{{header|C sharp|C#}}: Linked to element definition; added for-loop version) |
||
Line 382: | Line 382: | ||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
Uses the generic version of the node type located [[Singly-linked_list/Element_definition#C#|here]]. |
|||
Simple iteration with a while loop. |
|||
<lang csharp>//current is the first Link in the list |
|||
<lang csharp>var current = [head of list to traverse] |
|||
while(current != null) |
|||
System.Console.WriteLine(current.item); |
|||
{ |
|||
⚫ | |||
// Do something with current.Value. |
|||
⚫ | |||
}</lang> |
|||
Alternatively, as a for loop: |
|||
<lang csharp>for (var current = [head of list to traverse]; current != null; current = current.Next) |
|||
{ |
|||
// Do something with current.Value. |
|||
}</lang> |
}</lang> |
||