C++ Sorting Question

I’m working through the Silver>Sorting&Sets>Sorting with custom comparators page. Link to that page:

For the Wormhole sort example, they show two methods of sorting based on weight. With the first method, they create a vector of nested pairs. Then they use the sort method. How does the sort method automatically know to sort the vector based on the second nested pair value?

Similarly, in their second method of sorting, they make a vector of arrays. Again, how does the sort command know to sort it based on the third value of the array?

Any help would be well appreciated!

They actually sort it by the first element- it’s just that when processing the wormholes, they put the weight (w) at the front so it can be used by sort.