I was going through Chapter-11 when I couldn’t figure out how these PQ are being initialized/constructed. I’ve listed 2 examples here. I was also wondering if learning these hard to remember initializations is “truly necessary” to getting a job at say google, and if these constructors couldn’t be made simpler?
The algos for these problems are fairly straightforward but the syntax of these constructors are fairly involved.
Page-169 ebook:
priority_queue<string, vector, function<bool(string, string)>> min_heap( [] (const string&a, const string&b) { return a.size() >= b.size(); });
Confused by the above constructor/initialization of PQ variable ‘min_heap’.
What does [] refer to? I assume whatever is inside the parenthesis after ‘min_heap’ is the compare function.What constructor is being used from these two?
http://www.cplusplus.com/reference/queue/priority_queue/priority_queue/
explicit priority_queue (const Compare& comp = Compare(),
const Container& ctnr = Container());
template
priority_queue (InputIterator first, InputIterator last,
const Compare& comp = Compare(),
const Container& ctnr = Container());
Problem 11.1: Page- 171 ebook:
priority_queue<IteratorCurrentAndEnd, vector, greater<> > min_heap;
It’s not clear what role struct IteratorCurrentAndEnd is playing here. What does it specify in the constructor? Which constructor definition is being used?
From the constructors described at http://www.cplusplus.com/reference/queue/priority_queue/priority_queue/ they don’t match any.