Software Specification Exercises: Dynamic Frames in Dafny

Software Specification, MEIC @ IST, 2019/20

João F. Ferreira

 jff
## Instructions - You can use the arrow keys, PgDown and PgUp to browse these exercises - You can use Escape to see an overview - You can use Ctrl+Click to zoom in
## Introduction The goal of this lab is to specify and implement OOP code in Dafny. **First**, ensure that you have Dafny working in your PC. You can also run [Dafny online](https://rise4fun.com/Dafny), but the experience is not as good. *In these labs, I recommend you to use the IDE VS Code.*
### 0. Before you continue Make sure that you do all the exercises from previous sessions (if you haven't done so already).

1. Queue with even numbers

In Lecture 10 we specified and implemented a stack of odd integers (using a class invariant). Following the same approach, specify and implement a queue of even numbers.

2. Binary Trees

Continue working in the file Tree.dfy provided with Lecture 10. Ensure that your class invariant specifies a valid binary search tree. Also, implement the methods:

// RemoveMin() removes the minimum number
// in the tree. It returns the minimum and the new reference to the root.
method RemoveMin() returns (min: int, node: TreeNode?)

// Remove(x) removes element x from the tree, returning the
// new reference to the root
method Remove(x: int) returns (node: TreeNode?)

3. Linked Lists

Define a new class for polymorphic Linked Lists using the following internal representation:


class Node<T> {
  // element stored in the node
  var elem: T;
  // next node in the list, if any
  var next: Node?<T>;

...

}

Define a class invariant that characterizes acyclic linked lists. Also, define a constructor and methods for insertion and removal of an element. Define a method headthat returns the first element and another one, called tail that returns the tail of the list.