Hi I am in beginner level in C++. I am making my own priority queue class, I have instruction that I want to use the comparison operator(operator <) for determine best priority. So how can I use that in my priority class???.Here just I tried:
Code:
template<typename T>
class MyPQ
{
public:
vector<T> vecImp;
MyPQ()
{
vecImp.empty();
}
MyPQ(T &data)
{
push(data);
}
bool empty() const
{
if(vecImp.empty())
{
return true;
}else
{
return false;
}
}
void push(const T &data)
{
insertData(data);
vecImp.push_back(data);
}
T pop()
{
// pop code
}
T getData()
{
return data;
}
void insertData(const T& insert)
{
data=insert;
}
bool operator< (const MyPQ& Q1)
{
return data < Q1.data;
}
~MyPQ()
{
}
private:
T data;
};
So my problem where I can use the comparison method? in pop() method? or in the main routine?