Java Day 05

Source: Internet
Author: User

The second definition of an array

Array-Traversal
The core idea of array operation is the operation of diagonal mark;

Array-Find the most value
1. Cycle comparison

Sort
Select Sort to split the original array into two arrays, at least one is ordered
Bubble sort adjacent elements comparison

Location Substitution Code Extraction
Formal parameters

Sorting performance issues
Select Sort, and each wheel finds the minimum value before swapping a position

Find
Traverse to compare the value to find, no return-1

Binary find (binary search)
Prerequisites: Elements within an array are unique and orderly
Cyclic judging conditions are: intermediate value judgment;
"/2" relative to ">>1"

Returns the insertion point directly (-insertion point-1) If the found element does not exist

1      Public Static intBinarySearch (int[]arr,intkey) {2         intStart = 0;3         intEnd = Arr.length-1;4         intMid = (start+end)/2;5          while(end>start) {6             if(key==Arr[mid]) {7                 returnmid;8             }9             Else if(key>Arr[mid]) {TenStart = Mid+1; One}Else{ AEnd=mid-1;  -             } -Mid = (start + end)/2; the         } -         return-1; -}

Binary conversion
Convert to 16 binary--with Operation &15, unsigned right shift >>>4
(char) temp-10+ ' A '

Using Arrays--table-checking method

1      Public StaticString Trans (intNumintBaseintoffset) {2         Char[] CHS ={' 0 ', ' 1 ', ' 2 ', ' 3 ',3' 4 ', ' 5 ', ' 6 ', ' 7 ',4' 8 ', ' 9 ', ' A ', ' B ',5' C ', ' D ', ' E ', ' F '};6String ss= "";7          while(true){8             inttemp = num &Base;9ss= chs[temp]+SS;Tennum = num >>>offset; One             if(num==0) A                 returnSS; -         } -}


Integer.tobinarystring ()

Java Day 05

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.