Search
 
SCRIPT & CODE EXAMPLE
 

CPP

sort vector from largest to smallest

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	//sort vector from largest to smallest in cpp
	int n;
	cout << "Enter size of vector: ";
	cin >> n;

	vector<int> v(n);

	//fill vector
	for (int i = 0; i < n; i++)  cin >> v[i];
	
	//sort
	sort(v.begin(), v.end(),greater<int>());

	//print vector
	for (int i = 0; i < n; i++)  cout << v[i] << " ";

	cout << "
";

	return 0;
}
Comment

sort vector from smallest to largest

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	//sort vector from smallest to largest in cpp
	int n;
	cout << "Enter size of vector: ";
	cin >> n;

	vector<int> v(n);

	//fill vector
	for (int i = 0; i < n; i++)  cin >> v[i];
	
	//sort
	sort(v.begin(), v.end());

	//print vector
	for (int i = 0; i < n; i++)  cout << v[i] << " ";

	cout << "
";

	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: formated string std::cout 
Cpp :: int to string Using boost::lexical_cast 
Cpp :: c++ multiple if conditions 
Cpp :: sort vector in c 
Cpp :: Chef and the Wildcard Matching codechef solution in c++ 
Cpp :: DMA c/c++ 
Cpp :: C++ selectin file location using Win32 API 
Cpp :: c++ sort cout end 
Cpp :: 400 watt hour per kg 
Cpp :: SDL_BlitSurface 
Cpp :: crtdbg c++ 
Cpp :: avl tree c++ 
Cpp :: Snake Procession codechef solution in c++ 
Cpp :: how to merge string array in C++ 
Cpp :: c++ program to convert kelvin to celsius 
Cpp :: program in c++ for simple interest rate 
Cpp :: C++ Display Numbers from 1 to 5 
Cpp :: assignment of single field in struct in solidity 
Cpp :: # in c++ 
Cpp :: is plaindrome 
Cpp :: niet werkend 
Cpp :: Normal Initialisation of 3D Vector 
Cpp :: 2160. Minimum Sum of Four Digit Number After Splitting Digits leetcode solution in c++ 
Cpp :: how to use and in c++ 
Cpp :: Processing a string- CodeChef Solution in CPP 
Cpp :: 771. Jewels and Stones leetcode solution in c++ 
Cpp :: powers of 2 in cpp 
Cpp :: sort c++ array 
Cpp :: how to include a library in arduino 
Cpp :: c++ inline if 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =