博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
折半查找算法
阅读量:7233 次
发布时间:2019-06-29

本文共 1132 字,大约阅读时间需要 3 分钟。

1. 折半查找算法

//折半查找算法    public static int zhebanSearch(int a[],int n, int x){        int low,high,mid;        low=0;        high=n-1;        while(low<=high){            mid=(low+high)/2;            if(a[mid]==x){                return mid;            }else if(a[mid]>x){                high=mid-1;            }else{                low=mid+1;            }        }        return -1;    }

2. 折半查找算法使用示例

package com.cn.find;import java.util.Scanner;//折半查找public class ZhebanSearch {    public static final int SIZE=10;    //折半查找算法    public static int zhebanSearch(int a[],int n, int x){        int low,high,mid;        low=0;        high=n-1;        while(low<=high){            mid=(low+high)/2;            if(a[mid]==x){                return mid;            }else if(a[mid]>x){                high=mid-1;            }else{                low=mid+1;            }        }        return -1;    }        //快速排序的一次划分    public static int partition(int[] a,int left, int right){        int temp,l,r,p;        l=left;        r=right;        p=(left+right)/2;        temp=a[(left+right)/2];    //将中间元作为分界值        while(l
temp&&l

 

转载地址:http://czpfm.baihongyu.com/

你可能感兴趣的文章
设置tomcat为https访问
查看>>
我的友情链接
查看>>
oracle的触发器和应用
查看>>
Docker实践(五):Docker Compose
查看>>
我的友情链接
查看>>
介绍几个jsp页面传对象的方法
查看>>
我的Jakarta+Commons
查看>>
Bootstrap的使用
查看>>
python设置文字输出颜色
查看>>
WARNING:tornado.access:403 GET /websocket (::1) 1.00ms
查看>>
cocos creator游戏适配这事
查看>>
AngularJS - contorller app module
查看>>
CF666E. Forensic Examination
查看>>
apue第16章笔记
查看>>
Nvidia Driver
查看>>
NIO 相关解析
查看>>
Loj #2304. 「NOI2017」泳池
查看>>
面试技巧,如何通过索引说数据库优化能力,内容来自Java web轻量级开发面试教程...
查看>>
Python实现:某个用户登录后,查看自己拥有所有权限
查看>>
iOS微信朋友圈 评论点击姓名功能
查看>>