【发布时间】:2013-05-26 03:14:07
【问题描述】:
我在 Eiffel 做作业,但在执行我的 ensure 子句时遇到了问题。是否需要一些特殊的语法来包含变量或函数?
这是我的“put”函数的代码
put(key: K; value: V)
require
key /= void
local
tmp:ITEM[K,V]
do
create tmp.make(key, value)
list.put_front (tmp)
count := count + 1
ensure
count = old count + 1 and list.has(key, value)
end
这是'has'函数的代码
has(key:K; val:V):BOOLEAN
require
key /= void
local
flag: INTEGER
do
flag := 0
from
list.start
until
list.exhausted
loop
if list.item.getkey = key then
if list.item.getvalue = val then
flag := 1
end
end
list.forth
end
if flag = 1 then
Result := true
else
Result := false
end
ensure
--???
end
任务是通过链表实现一个地图adt。 'put' 函数将 item(key, value) 插入到列表中。 'has' 函数检查列表是否包含(键值)对。
任何帮助将不胜感激。
【问题讨论】:
-
具体的问题是什么?是编译错误吗?
标签: eiffel