我有这样的冒泡排序声明;
procedure Bubble_Sort (Data: in out List) is
sorted: Boolean := false;
last : Integer := Data'LAST;
temp : Integer;
begin
while (not (sorted)) loop
sorted := true;
for check in range Data'First..(last-1) loop
if Data(check) < Data(check+1) then
-- swap two elements
temp := Data(check);
Data(check) := Data(check+1);
Data(check+1) := temp;
-- wasn't already sorted after all
sorted := false;
end if;
end loop;
last := last - 1;
end loop;
end Bubble_sort;
我已经像这样定义了'数据':
Unsorted : constant List := (10, 5, 3, 4, 1, 4, 6, 0, 11, -1);
Data : List(Unsorted'Range);
'List'的类型定义是;
type List is array (Index range <>) of Element;
就行了
用于检入范围Data'Range循环
我错过了操作数错误。我该如何解决这个问题?
答案 0 :(得分:3)
删除range
关键字:
for check in Data'Range loop
range
关键字用于定义范围和子类型(有时是匿名的),使用“范围”属性时不需要。