Solution
= Solution
Use a finite <sequence> $q$ as abstract state, initially empty. One <Scala> interface is
``
trait DoubleEndedQueue {
def isEmpty: Boolean
def addLeft(x: Int): Unit
def getLeft(): Int
def addRight(x: Int): Unit
def getRight(): Int
}
``
The emptiness query has no <precondition>; its result is $q_0=\langle\rangle$ and its <postcondition> is $q=q_0$. Adding on the left has no <precondition> and gives $q=\langle x\rangle\mathbin{++}q_0$. Adding on the right gives $q=q_0\mathbin{++}\langle x\rangle$. Both return `Unit`.
Each removal requires a nonempty incoming <sequence>. `getLeft()` returns its first entry and leaves the remaining final <sequence>; `getRight()` returns its last entry and leaves the remaining initial <sequence>. These contracts remove exactly one occurrence, so duplicate values are permitted and do not collapse the <sequence> into a <set>.