Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Binary search -Java achieve     - Teamviewer not start in Linux (Linux)

- To share some very useful Vim command (Linux)

- Grep how to find files based on file contents in UNIX (Linux)

- Linux System Getting Started Learning: Join cron job in Linux (Linux)

- Linux Network Programming - raw socket instance: MAC Address Scanner (Programming)

- Android and OpenCV2.4.4 build an image processing framework (2013 edition) (Linux)

- Java String and StringBuffer and StringBuilder Comments (Programming)

- 10 useful Linux command line tips (Linux)

- Compile Android libwebcore.so error occurs when solving (Programming)

- Red Hat Enterprise Linux Server 6.5 installation GCC 4.9.2 (Linux)

- Autojump: an advanced cd command in the Linux file system fast navigation (Linux)

- Zabbix API and PHP configuration (Server)

- quotacheck command file can not be created aquota.user and aquota.group solutions (Linux)

- CentOS6 install Redis (Database)

- Difference Redhat5 and 6 YUM source configuration (Linux)

- JavaScript basic types and type conversion (Programming)

- Taught you how to install Ubuntu Linux (Linux)

- To teach you a trick to find the real IP address (Linux)

- OpenCV cvFindCornerSubPix () to find sub-pixel Corner (Programming)

- How Linux system password security guarantee (Linux)

  Binary search -Java achieve
  Add Date : 2018-11-21      
  Binary search is for a small to an array of large sorted to find a number val, first comparison to be looking for the number of val and intermediate value, if greater than the median, then in the middle right of the value to find; if the ratio of the median small , then the median left to find. It has been recursion. You know where to find val. If not found, then the output sequence there is no relevant data.

package com.PengRong.A;

public class BinaryFind {

    public static void main (String [] args) {
        // TODO Auto-generated method stub
        int [] arr = {1, 5, 9, 56, 78, 80, 85, 99}; // Note that the array needs from small to large sorted.
        // If more data needs to be sorted by the sorting algorithm can use binary search Hair
        BinFind binfin = new BinFind ();
        binfin.binaryFind (0, arr.length-1, 85, arr);

class BinFind
    / **
    * @param Left left array subscript
    * @param Right and an array subscript
    * @param Arr an array reference
    * @param Val to be looking for a few
    * @ Functions: a bunch of numbers to find whether there val number, call the binary search method provided that this is an orderly sequence arr
    * /
    public void binaryFind (int left, int right, int val, int [] arr)
        // Binary search is actually through the array must be such that no more than the right of the left subscript subscript
        if (left < = right)
            // Find the middle number
            int pivot = arr [(left + right) / 2];
            // If you're looking for the number is smaller than the median in the middle of the left to find value
            if (val < pivot)
                binaryFind (left, (left + right) / 2-1, val, arr);
            } Else if (val> pivot)
                // If you are looking for a number greater than the median in the middle right of the value to find
                binaryFind ((left + right) / 2 +1, right, val, arr);
            } Else if (val == pivot)
                System.out.println ( "found in the array sequence" + val + "this number, its index is:" + ((left + right) / 2));
            System.out.println ( "I'm sorry the number you are looking for is not in the array sequence");


- Simple steps allows you to build a more secure Linux server (Linux)
- Configuring Allatori code confusion when developing general Java applications in NetBeans (Programming)
- Linux system started to learn: how to solve the xxx is not in the sudoers file error (Linux)
- Nginx start, stop, smooth start, smooth upgrade (Server)
- LVM management reduces swap partition space to the root partition (Linux)
- awk pattern matching (Programming)
- Oracle common internal event tracking number (Database)
- How to build Memcached Docker container (Server)
- Grading defense against Linux server attacks (Linux)
- Installation Android IDE development tools, Android Studio 1.5 under Ubuntu (Linux)
- Replace element and non-replaced elements of learning (Programming)
- Restore database fault encountered ORA-0600 (Database)
- Linux operation and maintenance of the actual file system, file links (Linux)
- Ubuntu 14.04 to install file editor KKEdit 0.1.5 version (Linux)
- Examples of Exploration Class File (Programming)
- How to add and delete bookmarks in Ubuntu (Linux)
- Kafka cluster deployment (Server)
- Simple to install Tor browser to Ubuntu 14.04 and Linux Mint 17 (Linux)
- Ubuntu buffalo wzr-hp-300nh brush DD-WRT router system (Linux)
- SQL in the specific internal Oracle process (Database)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.