Doubly-linked list/Element definition: Difference between revisions
Content deleted Content added
→{{header|Pop11}}: Added PureBasic |
J |
||
Line 154: | Line 154: | ||
next = updateRight nr new |
next = updateRight nr new |
||
</lang> |
</lang> |
||
=={{header|J}}== |
|||
As discussed in [[Doubly-linked_list/Definition#J]], doubly linked lists are antithetical to J's design. Defining individual elements as independent structures is even worse. Now each element of the list must contain three arrays (everything in J is an array), all so that we can implement a list. |
|||
Yo Dawg, we heard you like lists, so we put lists in your lists so you can list while you list. |
|||
Nevertheless, this is doable, though it necessarily departs from the definition specified at [[Doubly-linked_list/Definition#J]]. |
|||
coclass'DoublyLinkedListElement' |
|||
create=:3 :0 |
|||
this=:coname'' |
|||
'predecessor successor data'=:y |
|||
successor__predecessor=: predecessor__successor=: this |
|||
) |
|||
Here, when we create a new list element, we need to specify its successor node and its predecessor node and the data to be stored in the node. To start a new list we will need a node that can be the head and the tail of the list -- this will be the successor node for the last element of the list and the predecessor node for the first element of the list: |
|||
coclass'DoublyLinkedListHead' |
|||
create=:3 :0 |
|||
predecessor=:successor=:this=: coname'' |
|||
) |
|||
=={{header|Java}}== |
=={{header|Java}}== |