Challenge: Sort Structs with a Lambda
Taak
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.
Oplossing
solution.cpp
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 3. Hoofdstuk 2
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Awesome!
Completion rate improved to 12.5
Challenge: Sort Structs with a Lambda
Veeg om het menu te tonen
Taak
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.
Oplossing
solution.cpp
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 3. Hoofdstuk 2
single