Is it possible to to have a custom comparator function for priority queue which keeps on changing. If not is their any way to implement this functionality. Ex:
#define fi first
#define se second
int X,Y;
struct comp
{
bool operator()(pair<int,int>& A, pair<int,int> & B)
{
int x1=A.fi,y1=A.se,x2=B.fi,y2=B.se;
if((abs(X-x1)+abs(Y-y1))>(abs(X-x2)+abs(Y-y2)))
{
return false;
}
else
return true;
}
};
////in MAin
X=1,Y=1;
priority_queue<pair<int,int>, vector<pair<int,int> >,comp>PQ;
for(int i=1;i<=N;i++)
{
for(int j=1;j<=M;j++)
{
if(i==1 && j==1) continue;
PQ.push(m_p(i,j));
}
}
cout<<1<<" "<<1<<endl;
while(!PQ.empty())
{
int x=PQ.top().fi;
int y=PQ.top().se;
cout<<x<<" "<<y<<endl;
PQ.pop();
X=x;Y=y;
}
as we keep on changing X,Y, our PQ will change itself accordingly?