Bipartite Java C # VB. NET

Source: Internet
Author: User

Java dichotomy

1 Public   Int Found ( Int A [], Int R ){
2 Int Start, end, middle, RS;
3 Start =   0 ;
4 End = A. length;
5 RS = R;
6
7 While (Start < End ){
8
9 Middle = (Start + End) /   2 ;
10
11 If (RS = A [Middle]) {
12 Return Middle;
13 }
14 If (RS < A [Middle]) {
15 End = Middle - 1 ;
16
17 }
18 If (RS > A [Middle]) {
19 Start = Middle + 1 ;
20 }
21 }
22 Return   - 1 ;
23
24 }

C # binary classification

Code

1 Public   Int Found ( Int [], Int R)
2 {
3 Int Start, end, middle, RS;
4 Start =   0 ;
5 End = A. length;
6 RS = R;
7 While (Start < End)
8 {
9 Middle = (Start + End) /   2 ;
10 If (RS = A [Middle])
11 {
12 Return Middle;
13 }
14 If (RS < A [Middle])
15 {
16 End = Middle -   1 ;
17 }
18 If (RS > A [Middle])
19 {
20 Start = Middle +   1 ;
21 }
22 }
23 Return   - 1 ;
24 }

 

VB. NET

Code

1 Public Function found (byval A as INTEGER (), byval R as integer) as integer
2 Dim start as integer, [end] As integer, middle as integer, RS as integer
3 Start =   0
4 [End] = A. Length
5 RS = R
6 While start < [End]
7 Middle = (Start + [End]) \ 2
8 If RS = A (middle) then
9 Return middle
10 End if
11 If RS < A (middle) then
12 [End] = Middle -   1
13 End if
14 If RS > A (middle) then
15 Start = Middle +   1
16 End if
17 End while
18 Return - 1
19 End Function

 

Related Article

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.