Question
I need to sort a list of first and last names. My names are stored in pairs with first being the first name and second
I need to sort a list of first and last names. My names are stored in pairs with first being the first name and second being the last name. Example:
make_pair("Josh", "Nahum")
I want to order by the second attribute (then ordering by the first attribute if the second attribute values are the same).
Example Sorted:
Hayam Abdelrahman
Doug Kirkpatrick
Josh Nahum
Zach Nahum
Charles Ofria
Write a function (named "sort_by_second") that takes a two const_iterators from a vector of pairs of string key and string value. The first iterator points at the first element, and the second iterator points at one past the last element (the end iterator).
It should return a new vector of pairs that is sorted according to the above specification. Do not change the original vector.
Starter Code:
#includeusing std::vector; #include using std::string; using Name = pair ; vector sort_by_second( const vector ::iterator & begin, const vector ::iterator & end) { }
use c++
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started