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

Andy had three more episodes like the one he’d had just an hour before the wedding

Can you hear me? — A quick guide to adding sound to a game in Unity

Android vs. iOS App Development: Which Is the Better Choice for Your Business in 2019?

FLOC Origin Trial: What We Observed (1/4)

Server-Side Rendering vs Client-Side Rendering — How does it impact SEO

Leetcode 1002. Find Common Characters

Function inside for loop not working

Mars Ecosystem Weekly Report #35

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

All About Oop in C++(blog #02)

Subject: Recursion… Recursion… Recur…

The CMSC 21 Experience for Me

Famous C++ Program that Every Programmer Should Know