A class of singly-linked mutable lists of integers.
MList
is very similar to hwtest.slist.SList, but
with the following differences:
head_=
andtail_=
method supporting assignment to the head and tail of a node.==
and hashing based on pointers rather than the contents of a node.- numerous complications related to the possibility
that an
MList
could contain a cycle.
Here's how the MList
s handle cycles:
- A cyclic list will be displayed as (for example)
MList(1, 2, *3, 4->*)
which indicates that the tail field of the 4 node points back to the 3 node. 2. Two cyclic lists are considered equivalent only if they have EXACTLY the same shape. For example, the following lists are arguably equivalent (because they all consist of a 1 followed by an infinite number of 2s) but are NOT considered equivalent by this package:
MList(1, *2->*)
MList(1, 2, *2->*)
MList(1, *2, 2->*)
- To write tests involving cyclic lists, use the format
(1 *2 3)
where the `*` indicates the beginning of the cycle.
The `*` must be followed by at least one element.
Whitespace is allowed between the `*` and the following
element.
- Companion:
- object
Value members
Abstract methods
Returns the first element of the list.
Returns the first element of the list.
Throws NoSuchElementException
if the list is empty.
Assigns a new value to the head of the list.
Assigns a new value to the head of the list.
Throws UnsupportedOperationException
if the list is empty.