杨氏查找矩阵
来源:互联网 发布:python np.split axis 编辑:程序博客网 时间:2024/05/16 01:15
1 2 5
3 4 7
6 8 9
从左到右递增,从上到下递增。如果要查找元素应该如何查找。
#include<iostream>using namespace std;#define COL 3#define ROW 3bool Young(int a[][COL],int search){ int i =0,j = COL-1; int tmp = a[i][j]; while (true){ if(tmp==search){ cout<<"a["<<i<<"]["<<j<<"]"; return true; } else if(tmp > search && j>0) tmp = a[i][--j]; else if(tmp < search && i<ROW -1) tmp = a[++i][j]; else return false; } }int main(){ int a[ROW][COL]={{1,2,3},{4,5,7},{6,8,9}}; cout<<Young(a,2); system("pause"); return 0; }
0 0
- 杨氏矩阵查找!
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏查找矩阵
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏矩阵查找
- 杨氏矩阵查找
- JAVA设计模式-工厂模式
- 操作系统的几个问题
- Linux下各个目录详细介绍
- 在相关网站首页加载到手机上浏览网页
- 原型模式
- 杨氏查找矩阵
- UVALive - 5088 Alice and Bob's Trip
- LinuxC下获取UDP包中的路由目的IP地址和头标识目的地址
- cout 格式化输出
- MTK Android Driver :battery
- 如何编译boot loader
- eclipse下使用hibernate tools实现hibernate逆向工程
- opengl glBindTexture为何失败
- ssh框架整合异常处理