Originally Posted by
anon
Code:
#include <vector>
#include <queue>
int main()
{
std::vector<std::vector<int> > v(100);
std::priority_queue<std::vector<int> > pq;
pq.push(v[1]);
}
This code made me think. How does priority_queue compare elements?
Code:
#include <vector>
#include <iostream>
#include <queue>
int main()
{
std::vector<std::vector<int> > v;
std::vector<int> temp;
temp.push_back(3);
temp.push_back(7);
temp.push_back(2);
v.push_back(temp);
temp.clear();
temp.push_back(13);
temp.push_back(17);
temp.push_back(12);
v.push_back(temp);
std::priority_queue<std::vector<int> > pq;
pq.push(v[0]);
pq.push(v[1]);
std::cout << pq.top()[0] << std::endl;
}
prints 13 for me. I was wondering if it just looked at the first element of the vector. What exactly is happening? I see it uses a template function
Code:
class Compare = less<typename Container::value_type>
but what is Container::value_type?