Anonymous user
Singly-linked list/Traversal: Difference between revisions
Updated first D entry
No edit summary |
(Updated first D entry) |
||
Line 145:
=={{header|D}}==
<lang d>struct SLinkedNode(T) {
T data;
typeof(this)* next;
while (a) {▼
Stdout(a.data) (" -> ");▼
a = a.next;▼
}</lang>▼
this(T data_, typeof(this)* next_=null) {
Or using tango's collections (written by Doug Lea, ported to D)▼
this.data = data_;
this.next = next_;
}
}
void main() {
<lang D>import tango.io.Stdout;▼
import std.stdio;
alias SLinkedNode!int N;
auto lh = new N(1, new N(2, new N(3, new N(4))));
auto p = lh;
}
writeln();
▲}</lang>
{{out}}
<pre>1 2 3 4 </pre>
===Alternative Version===
import tango.util.collection.LinkSeq;
Line 163 ⟶ 181:
m.append("charlie");
foreach (val; m)
Stdout
}</lang>
|