zoukankan      html  css  js  c++  java
  • 练习

    import java.util.Random;
    public class mytest {

        public static void main(String[] args) {
            Random rand = new Random();
            int[] aa ;
            int len = 100;
            aa = new int[len];
            for(int i = 0 ;i < len ;i++)
            {
                aa[i] = rand.nextInt(len);
            }
            //sort
            for(int i = 0 ; i < len ; i ++){
                for(int j = i ; j < len ; j ++){
                    if(aa[i]>aa[j]){
                        int tmp = aa[i];
                        aa[i] = aa[j];
                        aa[j] = tmp;
                    }
                }            
            }
            //print
            for(int i = 0 ; i < len ; i ++){
                System.out.println(aa[i]);            
            }
            System.out.println("--------------------------------------------");
            //find
            int searchVal = 77;
            int resultPos = searchInt(aa,searchVal,0,len);
            System.out.println(resultPos);

            System.exit(0);
        }
        
        public static int searchInt(int[] intArr,int searchV,int beginIndex,int endIndex){
            int modPs = beginIndex + ( endIndex - beginIndex ) / 2;
            if(intArr[modPs]==searchV){
                return modPs;
            }else if(endIndex < beginIndex || endIndex - beginIndex == 1){
                return -1;
            }else if(intArr[modPs]<searchV){
                beginIndex = modPs;
                return searchInt(intArr,searchV,beginIndex,endIndex);
            }else{
                endIndex = modPs;
                return searchInt(intArr,searchV,beginIndex,endIndex);
            }
        }
    }
  • 相关阅读:
    关于IIS的IUSER和IWAM帐户
    sql server 提取汉字/数字/字母的方法
    SQlserver创建函数实现只取某个字段的数字部分
    SQL中 EXCEPT、INTERSECT用法
    SQL中EXCEPT和Not in的区别?
    生成本月日历
    SQL打印全年日历
    SQL语句添加删除修改字段[sql server 2000/2005]
    SQL数据是否存在(是否有数据)判断,表,存储过程是否存在
    SQL时间相关
  • 原文地址:https://www.cnblogs.com/abinxm/p/2239079.html
Copyright © 2011-2022 走看看