Jump to content

Doubly-linked list/Definition: Difference between revisions

m
Switched Fortran with F# and PL/I with PicoLisp to restore alphabetic order
m (Switched Fortran with F# and PL/I with PicoLisp to restore alphabetic order)
Line 923:
loop_foreach_previous( Fun, Next ) -> Next ! {foreach_previous, Fun}.
</lang>
 
=={{header|F Sharp|F#}}==
<lang fsharp>type DListAux<'T> = {mutable prev: DListAux<'T> option; data: 'T; mutable next: DListAux<'T> option}
type DList<'T> = {mutable front: DListAux<'T> option; mutable back: DListAux<'T> option} //'
 
let empty() = {front=None; back=None}
 
let addFront dlist elt =
match dlist.front with
| None ->
let e = Some {prev=None; data=elt; next=None}
dlist.front <- e
dlist.back <- e
| Some e2 ->
let e1 = Some {prev=None; data=elt; next=Some e2}
e2.prev <- e1
dlist.front <- e1
 
let addBack dlist elt =
match dlist.back with
| None -> addFront dlist elt
| Some e2 ->
let e1 = Some {prev=Some e2; data=elt; next=None}
e2.next <- e1
dlist.back <- e1
 
let addAfter dlist link elt =
if link.next = dlist.back then addBack dlist elt else
let e = Some {prev=Some link; data=elt; next=link.next}
link.next <- e</lang>
 
 
=={{header|Fortran}}==
Line 1,142 ⟶ 1,173:
</pre>
 
=={{header|F Sharp|F#}}==
<lang fsharp>type DListAux<'T> = {mutable prev: DListAux<'T> option; data: 'T; mutable next: DListAux<'T> option}
type DList<'T> = {mutable front: DListAux<'T> option; mutable back: DListAux<'T> option} //'
 
let empty() = {front=None; back=None}
 
let addFront dlist elt =
match dlist.front with
| None ->
let e = Some {prev=None; data=elt; next=None}
dlist.front <- e
dlist.back <- e
| Some e2 ->
let e1 = Some {prev=None; data=elt; next=Some e2}
e2.prev <- e1
dlist.front <- e1
 
let addBack dlist elt =
match dlist.back with
| None -> addFront dlist elt
| Some e2 ->
let e1 = Some {prev=Some e2; data=elt; next=None}
e2.next <- e1
dlist.back <- e1
 
let addAfter dlist link elt =
if link.next = dlist.back then addBack dlist elt else
let e = Some {prev=Some link; data=elt; next=link.next}
link.next <- e</lang>
=={{header|Go}}==
Go has nothing like an enforced invariant. Responsibility for preventing circular loops must be shared by all code that modifies the list. Given that, the following declaration ''enables'' code to do that efficiently.
Line 1,610 ⟶ 1,612:
<pre>0 1 2 40 41 42
42 41 40 2 1 0</pre>
=={{header|PL/I}}==
<lang PL/I>
define structure
1 Node,
2 value fixed decimal,
2 back_pointer handle(Node),
2 fwd_pointer handle(Node);
</lang>
 
=={{header|PicoLisp}}==
Line 1,641 ⟶ 1,635:
(setq *DLst (2list 'was 'it 'a 'cat 'I 'saw))</lang>
For output of the example data, see [[Doubly-linked list/Traversal#PicoLisp]].
 
=={{header|PL/I}}==
<lang PL/I>
define structure
1 Node,
2 value fixed decimal,
2 back_pointer handle(Node),
2 fwd_pointer handle(Node);
</lang>
 
=={{header|PureBasic}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.