Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Sort Structs with a Lambda | Lambdas in the STL
C++ Lambda Expressions

bookChallenge: Sort Structs with a Lambda

Oppgave

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_lambda to compare two Student objects and return true if the first has a higher grade than the second.
  • Use this comparator with std::sort to sort the students vector.
  • Print each student's name and grade, one per line, in the format name: grade after sorting.

Løsning

solution.cpp

solution.cpp

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 2
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Suggested prompts:

Can you explain this in simpler terms?

What are the main points I should remember?

Can you give me an example?

close

Awesome!

Completion rate improved to 12.5

bookChallenge: Sort Structs with a Lambda

Sveip for å vise menyen

Oppgave

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_lambda to compare two Student objects and return true if the first has a higher grade than the second.
  • Use this comparator with std::sort to sort the students vector.
  • Print each student's name and grade, one per line, in the format name: grade after sorting.

Løsning

solution.cpp

solution.cpp

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 2
single

single

some-alt