why not start from middle(m/2, n/2) Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652
On Wed, Apr 4, 2012 at 12:29 AM, Karthikeyan V.B <kartmu...@gmail.com>wrote: > Hi, > > Start from right top corner > If matrix element > key move to previous column > else if matrix element < key move to next row > > int search(int** a,int key,int m,int n) > { > if (key < a[0][0] || key > a[m-1][n-1]) return 0; > int min=a[0][n-1],i=0,j=n-1; > while(i<=m-1 && j>=0) > { > if(a[i][j] > key) > j--; > else if(a[i][j] < key) > i++; > else > return 1; > } > return 0; > } > > Regards, > Karthikeyan.V.B > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.