stack::push()
:
stk.push()
when stk
is not full,
x
pushed into stk
.
x
on the top of stk
,
stk
.
i < n ∧ a[i] ≠ x
assert
statement.
assert
macro.
sort(T a[], int n) pre: n > -1 post: for all 0i j < n : a[i] < a[j]
class stack private: T data[max] unsigned top // Invariant: // 0 < max // 0 ≤ top ∧ top ≤ max // 0 < top → head ≡ data[top - 1]
|
|
sorted(data)
.
add(x)
uses insertion to add x
to data
.
add(x) data[end++] = x for (i = end - 1, i > 0, i--) if data[i - 1] ≤ data[i] break swap(data[i - 1], data[i])
{ INV ∧ prer(xr) } Br { INV ∧ postr(xr) }
{ DefaultC ∧ preC(xC) } BC { INV }