https://leetcode.com/problems/sort-array-by-increasing-frequency/
In this leetcode question, I wrote the following code:
class Solution {
public:
bool compare(pair<int,int>p1,pair<int,int>p2)
{
if(p1.second<p2.second)
return true;
else if(p1.second==p2.second)
{
if(p1.first>p2.first)
return true;
else
return false;
}
else
return false;
}
vector<int> frequencySort(vector<int>& nums) {
vector<int>final(nums.size());int k=0;map<int,int>mpp;
for(int i=0;i<nums.size();i++)
{
mpp[nums[i]]++;
}
sort(mpp.begin(),mpp.end(),compare);
for(auto it:mpp)
{
while(it.second)
{
final[k++]=it.first;
it.second--;
}
}
return final;
}
};
This gives me the following error:
Line 23: Char 36: error: reference to non-static member function must be called
sort(mpp.begin(),mpp.end(),compare);
^~~~~~~
Can someone please point out the mistake? (PS: I am new to Object Oriented Programming)