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