zoukankan      html  css  js  c++  java
  • 【c语言】二维数组中的查找,杨氏矩阵在一个二维数组中,每行都依照从左到右的递增的顺序排序,输入这种一个数组和一个数,推断数组中是否包括这个数

    //  二维数组中的查找,杨氏矩阵在一个二维数组中。每行都依照从左到右的递增的顺序排序。

    // 每列都依照从上到下递增的顺序排序。请完毕一个函数,输入这种一个数组和一个数。推断数组中是否包括这个数 #include <stdio.h> #define col 4 #define rol 4 int 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, 10, 11, 12 }, { 13, 14, 15, 16 } }; printf("%d ", yang(arr, 6)); printf("%d ", yang(arr, 15)); printf("%d ", yang(arr, 20)); printf("%d ", yang(arr, 1)); printf("%d ", yang(arr, 16)); return 0; }



    
    





  • 相关阅读:
    HTTP GET POST PUT DELETE 四种请求
    PHP表达式
    PHP基础
    文件存储
    动态加载布局文件
    Android新增控件
    Spring简介
    Hibenate配置篇
    无题
    struts常用标签与校验器
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/6803492.html
Copyright © 2011-2022 走看看