Search for the existence of a number in a two-dimensional array increasing by row and column

Source: Internet
Author: User

Search for the existence of a number in a two-dimensional array increasing by row and column

Unique requirement: Two-dimensional arrays increase progressively by Column

Clever Use of the characteristics of the Bipartite method, first compared with the element in the upper right corner, greater than row + 1, less than column-1, otherwise return the row and column

# Include <iostream> using namespace std; # define M 3 void array_bsearch (int array [] [M], int value) {int I = 0; // line int j = M-1; // column while (I <sizeof (array)/M) while (j> = 0) {if (value> array [I] [j]) {I + = 1;} else if (value <array [I] [j]) {j-= 1 ;} else {cout <I <"" <j <endl; // return ;}} cout <"value does not exist" <endl ;} void main (void) {int array [] [M] = {1, 2, 3}, {4, 5, 6}, {7, 8, 9 }}; array_bsearch (array, 1 );}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.