点击(此处)折叠或打开
#include<iostream> using namespace std; //const int COL = 4; //const int ROW = 4; bool find(int **array,int Col,int Row,int searchKey)//注意这里的参数传递 { int row = 0; int col = Col-1; // int compare = array[0][COL-1]; while (1) { if (array[row][col] == searchKey) { return true; } else if (array[row][col] > searchKey && row < Row-1) { ++row; } else if (array[row][col] < searchKey && col >= 0) { --col; } else return false; } } int main() { int COL,ROW; cin >> COL; cin >> ROW; int **a = new int *[ROW]; for (int i = 0;i < COL;i++) { a[i] = new int[COL]; } for (int i = 0;i < ROW;i++) { for (int j = 0;j < ROW;j++) cin >> a[i][j]; } // int a[][4] = {1,2,8,9,2,4,9,12,4,7,10,13,6,8,11,15}; cout << find(a,COL,ROW,18)<< endl; return 0; } <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> 阅读(132) | 评论(0) | 转发(0) | 0上一篇:linux内核的一点总结
下一篇:内存管理
相关热门文章 test123编写安全代码——小心有符号数...使用openssl api进行加密解密...一段自己打印自己的c程序...彻底搞定C语言指针详解-完整版... 给主人留下些什么吧!~~ 评论热议