Singly-linked list/Element removal: Difference between revisions

Realize in F# (reluctantly)
(Realize in F# (reluctantly))
Line 633:
Item not found</pre>
 
=={{header|F_Sharp|F#}}==
Not really a functional thing to do but...
<lang fsharp>
// Singly-linked list/Element removal. Nigel Galloway: March 22nd., 2022
let N=[23;42;1;13;0]
let fG n g=List.indexed n|>List.filter(fun(n,_)->n<>g)|>List.map snd
printfn " before: %A\nand after: %A" N (fG N 2)
</lang>
{{out}}
<pre>
before: [23; 42; 1; 13; 0]
and after: [23; 42; 13; 0]
</pre>
=={{header|Fortran}}==
This sort of thing has long been done in Fortran via the standard trick of fiddling with arrays, and using array indices as the equivalent of the memory addresses of nodes. The task makes no mention of there being any content associated with the links of the linked-list; this would be supplied via auxiliary arrays or disc file records, ''etc''. With F90 and later, one can define compound data aggregates, so something like LL.NEXT would hold the link to the next element and LL.STUFF would hold the cargo, with LL being an array of such a compound entity rather than separate simple arrays such as LLNEXT and LLSTUFF.
2,172

edits