Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

#include  using 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions