Re: [algogeeks] matrix finding immediate neighour

2011-08-25 Thread Neha Singh
//Checks whether x is greater than y
int check(int x,int y)
{
if(x>y)
return 1;
else
return 0;
}

//Checks if the element at location i,j is the local maxima
int checkIfMaxima(int mat[][],int i,int j,int maxi,int maxj)
{
int c;
if(i-1 >= 0)
{
c=check(mat[i][j],mat[i-1][j]);
if(!c)
return 0;   //Means mat[i][j] is not the local maxima
}
if(j-1 >= 0)
{
c=check(mat[i][j],mat[i][j-1]);
if(!c)
return 0;   //Means mat[i][j] is not the local maxima
}
if(i+1 <= maxi)
{
c=check(mat[i][j],mat[i+1][j]);
if(!c)
return 0;   //Means mat[i][j] is not the local maxima
}
if(j+1 <= maxj)
{
c=check(mat[i][j],mat[i][j+1]);
if(!c)
return 0;   //Means mat[i][j] is not the local maxima
}
return 1;//Means mat[i][j] is the local maxima.
}

//Returns the list of local maxima locations in the matrix
List findLocalMaximas(int mat[][],int maxi,int maxj)
{
int i,j,flag;
List list;
for(i=0;i<=maxi;i++)
{
for(j=0;j<=maxj;j++)
{
flag=checkIfMaxima(mat,i,j,maxi,maxj);
if(flag)
AddToList(list,i,j);
}
}
return list;
}




I hv not provided the details of the list implementation. But it can be
easily implemented .


Neha Singh

-- 
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.



[algogeeks] matrix finding immediate neighour

2011-08-25 Thread tech coder
write a code which will receive as input a matrix (int[][] matrix) and which
should find all local maximum from the matrix. A local maximum is such a
number in the matrix that is greater than all its immediate neighbors. The
method should return the List of locations of all local maximum numbers
found.

-- 
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.