MList

sealed abstract class MList

A class of singly-linked mutable lists of integers.

MList is very similar to hwtest.slist.SList, but with the following differences:

  1. head_= and tail_= method supporting assignment to the head and tail of a node.
  2. == and hashing based on pointers rather than the contents of a node.
  3. numerous complications related to the possibility that an MList could contain a cycle.

Here's how the MLists handle cycles:

  1. 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->*)
  1. 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
class Object
trait Matchable
class Any

Value members

Abstract methods

def head: Int

Returns the first element of the list.

Returns the first element of the list.

Throws NoSuchElementException if the list is empty.

def head_=(newHead: Int): Unit

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.

def tail: MList

Returns the rest of the list without the first element.

Returns the rest of the list without the first element.

Throws UnsupportedOperationException if the list is empty.

def tail_=(newTail: MList): Unit

Assigns a new value to the tail of the list.

Assigns a new value to the tail of the list.

Throws UnsupportedOperationException if the list is empty.

Concrete methods

def ::(elem: Int): MList

Adds an element to the front of the list.

Adds an element to the front of the list.

def isEmpty: Boolean

Tests whether the list is empty.

Tests whether the list is empty.

def nonEmpty: Boolean

Tests whether the list has at least one element.

Tests whether the list has at least one element.

override def toString(): String
Definition Classes
Any