struct Point
{
double x;
double y;
double z;
};
int main()
{
auto comparator = [](Point p1, Point p2)
{
return p1.z > p2.z;
};
priority_queue<Point, vector<Point>, decltype(comparator)> pq(comparator);
pq.push({ 1,1,4 });
pq.push({ 1,1,2 });
pq.push({ 1,1,5 });
pq.push({ 1,1,1 });
pq.push({ 1,1,9 });
pq.push({ 1,1,6 });
pq.push({ 1,1,4 });
pq.push({ 1,1,3 });
while (!pq.empty())
{
Point p = pq.top();
pq.pop();
printf("%.4f %.4f %.4f\n", p.x, p.y, p.z);
}
return 0;
}
struct Point
{
double x;
double y;
double z;
friend bool operator < (Point p1, Point p2)
{
return p1.z > p2.z;
};
};
int main()
{
priority_queue<Point> pq;
pq.push({ 1,1,4 });
pq.push({ 1,1,2 });
pq.push({ 1,1,5 });
pq.push({ 1,1,1 });
pq.push({ 1,1,9 });
pq.push({ 1,1,6 });
pq.push({ 1,1,4 });
pq.push({ 1,1,3 });
while (!pq.empty())
{
Point p = pq.top();
pq.pop();
printf("%.4f %.4f %.4f\n", p.x, p.y, p.z);
}
return 0;
}
网友评论