Challenge: Sort Structs with a Lambda
Swipe to start coding
Implement the lambda comparator for sorting students by grade in descending order inside the provided my_lambda function. The function should return a std::function<bool(const Student&, const Student&)> that serves as the comparator for std::sort.
- Implement the lambda inside
my_lambdato compare twoStudentobjects and returntrueif the first has a higher grade than the second. - Use this comparator with
std::sortto sort thestudentsvector. - Print each student's name and grade, one per line, in the format
name: gradeafter sorting.
Løsning
solution.cpp
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Can you explain this in simpler terms?
What are the main points I should remember?
Can you give me an example?
Awesome!
Completion rate improved to 12.5
Challenge: Sort Structs with a Lambda
Sveip for å vise menyen
Swipe to start coding
Implement the lambda comparator for sorting students by grade in descending order inside the provided my_lambda function. The function should return a std::function<bool(const Student&, const Student&)> that serves as the comparator for std::sort.
- Implement the lambda inside
my_lambdato compare twoStudentobjects and returntrueif the first has a higher grade than the second. - Use this comparator with
std::sortto sort thestudentsvector. - Print each student's name and grade, one per line, in the format
name: gradeafter sorting.
Løsning
solution.cpp
Takk for tilbakemeldingene dine!
single