Doubly-linked list/Definition: Difference between revisions

no edit summary
m (→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations, moved the boxed comments to a separate section in the REXX preamble.)
No edit summary
Line 1,646:
2 fwd_pointer handle(Node);
</lang>
 
=={{header|PowerShell}}==
Create and populate the list:
<lang PowerShell>
$list = New-Object -TypeName 'Collections.Generic.LinkedList[PSCustomObject]'
 
for($i=1; $i -lt 10; $i++)
{
$list.AddLast([PSCustomObject]@{ID=$i; X=100+$i;Y=200+$i}) | Out-Null
}
 
$list
</lang>
{{Out}}
<pre>
ID X Y
-- - -
1 101 201
2 102 202
3 103 203
4 104 204
5 105 205
6 106 206
7 107 207
8 108 208
9 109 209
</pre>
Insert a value at the head:
<lang PowerShell>
$list.AddFirst([PSCustomObject]@{ID=123; X=123;Y=123}) | Out-Null
 
$list
</lang>
{{Out}}
<pre>
ID X Y
-- - -
123 123 123
1 101 201
2 102 202
3 103 203
4 104 204
5 105 205
6 106 206
7 107 207
8 108 208
9 109 209
</pre>
Insert a value in the middle:
<lang PowerShell>
$current = $list.First
 
while(-not ($current -eq $null))
{
If($current.Value.X -eq 105)
{
$list.AddAfter($current, [PSCustomObject]@{ID=345;X=345;Y=345}) | Out-Null
break
}
 
$current = $current.Next
}
 
$list
</lang>
{{Out}}
<pre>
ID X Y
-- - -
123 123 123
1 101 201
2 102 202
3 103 203
4 104 204
5 105 205
345 345 345
6 106 206
7 107 207
8 108 208
9 109 209
</pre>
Insert a value at the end:
<lang PowerShell>
$list.AddLast([PSCustomObject]@{ID=789; X=789;Y=789}) | Out-Null
 
$list
</lang>
{{Out}}
<pre>
ID X Y
-- - -
123 123 123
1 101 201
2 102 202
3 103 203
4 104 204
5 105 205
345 345 345
6 106 206
7 107 207
8 108 208
9 109 209
789 789 789
</pre>
 
=={{header|PureBasic}}==
308

edits