二维数组中的查找问题



171932470322375.png源代码

   
  1. #ifndef SEARCHDATA_TWODIMENSION_H
  2. #define SEARCHDATA_TWODIMENSION_H
  3. #include<iostream>
  4. int searchData_TwoBinaryArray(int *arr,int lineNum,int columnNum ,int searchData){
  5. int columnIndex=columnNum-1;
  6. int lineIndex=0;
  7. while(columnIndex>=0&&lineIndex<=lineNum-1&&arr!=NULL){
  8. if(arr[lineIndex*lineNum+columnIndex]>searchData){
  9. columnIndex--;
  10. }else if(arr[lineIndex*lineNum+columnIndex]<searchData){
  11. lineIndex++;
  12. }else{
  13. return 1;
  14. }
  15. }
  16. return 0;
  17. }
  18. #endif
171932470322375.png 测试代码

   
  1. int main(){
  2. int arr[16]={1,2,8,9,2,4,9,12,4,7,10,13,6,8,11,15};
  3. std::cout<<searchData_TwoBinaryArray(arr,4,4,7)<<std::endl;
  4. }













转载于:https://www.cnblogs.com/yml435/p/4655501.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值