Tag: 不变量

我怎么写这个不变量的循环?

这些是算法的断言,用于查找数组b [hk]的最小值: Precondition: h <= k < b.length Postcondition: b[x] is the minimum of b[h…k] 这是这个不变量的正确循环吗? 不变量:b [x]是b [h … t]的最小值 int x = t; int t = h; // {inv: b[x] is the minimum of b[h…t]} while (t != k) { t = t+1; if (b[t] < b[x]) { x = t;} }

计算机术语中的前置条件,后置条件和不变量有什么区别

我正在阅读Java Concurrency in Practice这本书,并对这些术语感到困惑: 预备条件 发布条件 不变 有人可以解释他们(举个例子,如果可能的话)?