STL Vectors — Print two highest values in list in descending order

vector<int> numbers = {5, 13, 7, 24};
sort(nums.rbegin(), nums.rend());
sort(nums.begin(), nums.end(), greater<int>());
cout << nums[0] << ", " << nums[1] << endl;

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Suppress “Used to extend current API with Koin API”

CS373 Spring 2020: Rithvik Saravanan — Blog Post #3

Make or Break, more than a hackathon!

Top-must use Free-Tier Amazon Web Services | Getting Started

How to ensure all of our models and subsystems are centered on the screen and are at 100% zoom?

Micro frontends — from tribes to nations and back

Deep Dive on Parameters

ZigZag Conversion — Day 71(Python)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Privalov Vladimir

Privalov Vladimir

More from Medium

Work with integers as binary in C++

Binary Exponentiation

CUDA: Tiled matrix-matrix multiplication with shared memory

Advent Of Code 2021 — Sonar Sweep — Puzzle 1