Young's matrix search

Source: Internet
Author: User

/***** Query the Young's matrix, that is, the right and bottom elements of any element in the matrix are greater than it, the elements on the left and bottom are smaller than **/public class MatriFind {/***** @ param a matrix to be searched * @ param width * @ param height Matrix * @ param num of */public void find (int a [] [], int width, int height, int num) {// point the pointer to the last element of the first row int xPos = width-1; int yPos = 0; while (xPos> = 0 & yPos <= height-1) {if (a [xPos] [yPos] = num) {System. out. println ("xPos:" + xPos + "yPos:" + yPos); return;} else If (a [xPos] [yPos]> num) {xPos --;} else {yPos ++;} System. out. println ("not found! ");} Public static void main (String [] args) {MatriFind mf = new MatriFind (); int matrix [] [] = {1, 2, 8, 9}, {2, 4, 9, 12}, {,}, {6, 8, 11, 15}; mf. find (matrix, matrix [0]. length, matrix. length, 10 );}}

 

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.