Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Sort Structs with a Lambda | Lambdas in the STL
C++ Lambda Expressions

bookChallenge: 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_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.

Рішення

solution.cpp

solution.cpp

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 2
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

close

Awesome!

Completion rate improved to 12.5

bookChallenge: 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_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.

Рішення

solution.cpp

solution.cpp

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 2
single

single

some-alt