25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 13. Statements<br />

✡✝<br />

(dcl z:nat := x;<br />

dcl m:\keyw{nat} := l(z);<br />

-- find min val in l(x..y)<br />

for i = x to y do<br />

if l(i) < m<br />

then ( m := l(i);<br />

z := i);<br />

-- move min val to index x<br />

(dcl temp:nat;<br />

temp := l(x);<br />

l(x) := l(z);<br />

l(z) := temp;<br />

x := x+1));<br />

✆<br />

BubbleMax operates in a similar fashion. It iterates through the subsequence to find the<br />

index of the maximum value, then swaps the contents of this index with the contents of the<br />

last element of the subsequence.<br />

✞<br />

✡✝<br />

BubbleMax : () ==> ()<br />

BubbleMax () ==<br />

(dcl z:nat := x;<br />

dcl m:nat := l(z);<br />

-- find max val in l(x..y)<br />

for i = x to y do<br />

if l(i) > m<br />

then ( m := l(i);<br />

z := i);<br />

-- move max val to index y<br />

(dcl temp:nat;<br />

temp := l(y);<br />

l(y) := l(z);<br />

l(z) := temp;<br />

y := y-1));<br />

✆<br />

13.9 The Call Statement<br />

Syntax: statement = . . .<br />

| call statement<br />

| . . . ;<br />

111

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!