公司NX二次开发_第1页
公司NX二次开发_第2页
公司NX二次开发_第3页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、else if (dis= min) tmp.add(i nt)nu m); buffer.addra nge(tmp); public static void main(String args) ArrayList array = new ArrayList(); array.add(26);array.add(76);array.add(46);array.add(76);array.add(54);array.add(94);array.add(24); array.add(34);int targetNum= 74;System.out.println(”和要查找的数:+targetN

2、um+ 最接近的数+bin arysearchKey(array.toArray(), targetNum);*遍历数组和要查找的数值做差,以差:数组索引存为map,然后对以差为key的数组排序,拿到差最小的索引。*paramarray*paramnumreturnpublic static In teger searchKey(i nt array,i nt num) in t temp = new in tarra y.len gth;Map map = new TreeMapv In teger,I nteger(); int dis num = 0;for (int i = 0; i

3、array.len gth; i+) dis num = Math.abs(arrayi - nu m);tempi=dis num;map.put(dis nu m, i);System.out.pri ntl n(数组和的差值和数组兀素的差值相减的绝对值和位置的映射结果: + map);Arrays.sort(temp);In teger in dex = map.get(temp0);System.out.println(”数组和的差值和数组元素的差值相减的绝对值最小值: +temp0+最小值的 key : + arrayindex);retur n(In teger) arrayi n

4、dex;/*求一个数组的最大值array1param*/ public static void max1(int array1) int max = 0;for (int i : array1) max = Math.max(max, i);System.out.pri ntl n(” 数组最大值是:+max);*求一个数组的最大值 public static void max2(i nt arrayl) int max = 0;for (int i = 0; i array1i ? max : array1i;System.out.pri ntl n(” 数组最大值是:+max);/*arr

5、ay1param*/ public static void max3(int array1) Arrays.sort(array1);System.out.pri ntln(” 数组最大值是:+array1array1.le ngth-1); 原如何在数组中查找定位最接近的数值Mar 22 2014作者:bianbian 发布:2014-03-22 11:18 分类:IDL/ENVI , Technology 阅读:78 浏览数 抢沙发这个需求一般是查询一个look-up-table ,比如数据定标表,假设有如下一个数组(实际数组比这大很多,只是为了举例):现在要找1.5最接近的数值:1234

6、我一开始用的是先把数组sort,然后用二分法查找(代码不贴了,很简单)后来一想IDL应该有内置支持这种查找吧,发现有Value_Locate 方法,可以解决问题。但是缺点很明显,需要先 sort后来找到这里:Locat ing a Value in an Array我稍微改进了一下,因为 Min支持/ABSOLUTE参数:1234标签:IDL, Min如果lz不懂算 法,或者懒 得想这些,懒人推荐C#或者VB.NET,因为有 LINQ。看代码:using System;using System.Collectio ns;usingSystem.Collectio ns.Ge neric;usi

7、ngSyste m丄inq;using System.Text;n ear).OrderBy(x =namespace ConsoleApplication1classProgramstaticvoidMai n(stri ngargs)intarray=newint5,3,9,11,14,8, 21,1,17,12,9,30;intn ear =10;varresult:=(fromx in4,2,6,12,3,7,18,21,20,7array selectnew Key = x,Value = Math.Abs(xx.Value);result.ToList().ForEach(x= C

8、onsole.Write(x.Key + ); using System;using System.Collectio ns;usingSystem.Collectio ns.Ge neric;usingSyste m丄inq;using System.Text;namespace ConsoleApplication1 class Program12345678 的数。l() select rderBy(x 度 take=10voidMai n(stri ngargs)Random r =new Random();intarray=new int1000000;for(int i=0; i Console.Write(x.Key +IIII);result.ToList().ForEach(x没理解错的话,一个循环就够了吧:dim adim n as longdim Idx as Ion g,dim i as long a=array(-2,-30,1,3,5

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论