Find in "C" two-dimensional array, Young's matrix in a two-dimensional array, each row is sorted in ascending order from left to right, enter an array and a number to determine if the array contains this number

Source: Internet
Author: User
  Find in a two-dimensional array, the young matrix in a two-dimensional array, each row is ordered in ascending order from left to right.  Each column is sorted in ascending order from top to bottom. Complete a function, enter an array and a number to determine if the array contains this number # include <stdio.h> #define COL 4#define rol 4int yang (int (*p) [col], int num) { int i = 0;int j = col-1;while (j+1) {int *q = & (P[i][j]), if (*q = num) return 1;else if (*q < num) {p++;} else if (*q > num) {--q;--j;}} return-1;} int main () {int Arr[rol][col] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, ten, one, and};p rintf ("%d\n", ya Ng (arr, 6));p rintf ("%d\n", Yang (arr.));p rintf ("%d\n", Yang (arr.));p rintf ("%d\n", Yang (arr, 1));p rintf ("%d\n", Yang (arr, +)); return 0;}





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Find in "C" two-dimensional array, Young's matrix in a two-dimensional array, each row is sorted in ascending order from left to right, enter an array and a number to determine if the array contains this number

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.