本文介绍了找到数组中的最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好, 我有一个包含4个值的数组(它们包含随机数)。我想 喜欢找到最低价值(如果有领带我想找到一个 领带。)然后删除该值。我是Programming and C#的新手。 感谢您提供的任何帮助 Thomas 解决方案 如果它总是4个元素则可能: minval = Math.Min(Math.Min(a [0 ],a [1]),Math.Min(a [2],a [3])); Arne 当你说...然后删除那个值。,你的意思是在 过程之后,你应该有一个低值,一个只有三个元素的数组? Lilith和Arne回答了排序问题。 " ThomasT22"写道: 是的,但是排序是破坏性的,并且是一种非常低效的方式来找到 中最低的四个数字。由于删除的要求已经明确规定, 我将在这里忽略它。为了找到最低值,我绝对不会使用Sort或Math.Min或Max。。为了最大限度地提高效率,可以使用以下内容: int a = x [0]; int b = x [1]; int c = x [2]; int d = x [3]; //有效地a = Math.Min(a,b) if(b< a) { a = b; } //有效地a = Math.Min(c,d) if(d< ; c) { c = d; } //有效地数学 .Min(a,c)其中总的来说是Math.Min(a, b,c,d) 返回(a< c)? a:c; 希尔顿 Hello,I have an array that holds 4 values ( they contain random numbers). I wouldlike to find the lowest value (if there is a tie i would like to find one ofthe tie.) then remove that value. I am new to Programming and C#.Thanks for any help you can provideThomas 解决方案If it is always 4 elements then maybe:minval = Math.Min(Math.Min(a[0], a[1]), Math.Min(a[2], a[3]));ArneYeah, but sorting is destructive and a very inefficient way to find thelowest of four numbers. Since the ''remove'' requirement was well specified,I''m going to ignore it here. To find the lowest value, I definitelywouldn''t use a Sort or Math.Min or Max. To maximize efficiency, somethingalong the lines of:int a = x[0];int b = x[1];int c = x[2];int d = x[3];// Effectively "a = Math.Min (a, b)"if (b < a){a = b;}// Effectively "a = Math.Min (c, d)"if (d < c){c = d;}// Effectively "Math.Min (a, c)" which in summary is really "Math.Min (a,b, c, d)"return (a < c) ? a : c;Hilton 这篇关于找到数组中的最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-30 10:06