查找阿达的Array最大值 [英] Find Maximum Value in Array in Ada
本文介绍了查找阿达的Array最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做的有很多不同的功能与阵列搞乱一个阿达项目,我得到了我的所有排序功能走,现在我被困在用不变的循环来设计该功能的循环数组中获取最大价值。任何帮助吗?
I am doing an Ada program with lots of different functions messing with arrays, i got all my sorting functions going, i am now stuck on retrieving the maximum value in an array using a loop invariant to design the loop for that function. any help?
推荐答案
如何简单地通过整个数组循环?
How about simply looping over the whole array?
是这样的:
function Get_Maximum (Of : My_Array_Type) return Element_Type is
Maximum : Element_Type := Of (Of'First);
begin
for I in Of'First + 1 .. Of'Last loop
if Of (I) > Maximum then
Maximum := Of (I);
end if;
end loop;
return Maximum;
end Get;
如果将数组为空,引发异常,但这是留给读者一个锻炼; Tibial,如果需要这些情况。
will raise an exception if the array is empty, but this is left as an excercise for the reader, if those cases are needed.
这篇关于查找阿达的Array最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文