Today's tutorial focuses on Abstract Data Types (ADTs) and how to implement them in PLT Scheme's object/class system. These concepts are introduced in Lecture Modules 3 and 4 (see Handouts).

- Double-ended queue
- The
**enqueue-front**operation has two arguments: an item`e`and a DEQ`D`=`d`_{1},`d`_{2}, ...,`d`_{n}, with precondition "true". The postcondition is that`D`=`e`,`d`_{1},`d`_{2}, ...,`d`_{n}, and no value is produced. - The
**enqueue-rear**operation has two arguments: an item`e`and a DEQ`D`=`d`_{1},`d`_{2}, ...,`d`_{n}, with precondition "true". The postcondition is that`D`=`d`_{1},`d`_{2}, ...,`d`_{n},`e`, and no value is produced. - The
**dequeue-front**operation has one argument, a DEQ`D`=`d`_{1},`d`_{2}, ...,`d`_{n}, with precondition n > 0. The postcondition is that`D`=`d`_{2},`d`_{3}, ...,`d`_{n}, and the value`d`_{1}is produced. - The
**dequeue-rear**operation has one argument, a DEQ`D`=`d`_{1},`d`_{2}, ...,`d`_{n-1},`d`_{n}, with precondition n > 0. The postcondition is that`D`=`d`_{1},`d`_{2}, ...,`d`_{n-1}, and the value`d`_{n}is produced. - The
**DEQ-empty**operation has one argument, a DEQ`D`=`d`_{1},`d`_{2}, ...,`d`_{n}, with precondition "true". The postcondition is "true", and the value "true" is produced if and only if`n`=0. - Playing Cards
- The
**get-rank**operation takes a Card (`r`,`s`) and produces the rank`r`of that Card. - The
**get-suit**operation takes a Card (`r`,`s`) and produces the suit`s`of that Card. - The
**rank-equals**operation takes two cards,`C`_{1}= (`r`_{1},`s`_{1}) and`C`_{2}= (`r`_{2},`s`_{2}), and returns "true" if and only if they have the same rank, i.e.`r`_{1}=`r`_{2}. - The
**rank-lessthan**operation takes two cards,`C`_{1}= (`r`_{1},`s`_{1}) and`C`_{2}= (`r`_{2},`s`_{2}), and returns "true" if and only if the rank of`C`_{1}is less than the rank of`C`_{2}, i.e.`r`_{1}<`r`_{2}. - The
**suit-equals**operation takes two cards,`C`_{1}= (`r`_{1},`s`_{1}) and`C`_{2}= (`r`_{2},`s`_{2}), and returns "true" if and only if they have the same suit, i.e.`s`_{1}=`s`_{2}. - The
**card-equals**operation takes two cards,`C`_{1}= (`r`_{1},`s`_{1}) and`C`_{2}= (`r`_{2},`s`_{2}), and returns "true" if and only if they have the same rank and suit, i.e.`r`_{1}=`r`_{2}and`s`_{1}=`s`_{2}.

Here is a description of the double-ended queue (DEQ) ADT:

A DEQ is a (possibly empty) sequence of values
`d`_{1}, `d`_{2}, ...,
`d`_{n}.
There are five operations on DEQs, as follows:

Implement the double-ended queue ADT as a class called `DEQ%`

in Scheme.

The following is a description of the Card ADT:

A Card is a pair (`r`,`s`), where `r` (the "rank")
is an integer in the range [1,13], and `s` (the "suit")
is one of the four words "spades", "hearts", "clubs", or "diamonds".
Cards are immutable, and so all preconditions and postconditions of all
operations are "true". A Card has the following operations:

Implement the Card ADT as a class called `card%`

in Scheme.

Last modified on Saturday, 11 August 2018, at 22:52 hours.