标签:
参考自剑指Offer
July的博客
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #define ROW 4 5 #define COL 4 6 7 void Young(int array[][COL], int key) 8 { 9 int i = ROW - 1; 10 int j = 0; 11 int val; 12 13 while (i>=0 && j<COL) 14 { 15 val = array[i][j]; 16 if (val == key) 17 { 18 printf("Find! [%d,%d]\n", i, j); 19 return; 20 } 21 if (val < key) 22 { 23 j ++; 24 } 25 26 if (val > key) 27 { 28 i --; 29 } 30 } 31 printf("Not Find!\n"); 32 } 33 34 int main() 35 { 36 int array[ROW][COL] = {{1,2,8,9},{2,4,9,12},{4,7,10,13},{6,8,11,15}}; 37 int key = 100; 38 Young(array, key); 39 return 0; 40 }
标签:
原文地址:http://www.cnblogs.com/Juntaran/p/5800604.html