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.

Reply via email to