c++ sort
#include<bits/stdc++.h>
vector<int> v = { 6,1,4,5,2,3,0};
sort(v.begin() , v.end()); // {0,1,2,3,4,5,6} sorts ascending
sort(v.begin(), v.end(), greater<int>()); // {6,5,4,3,2,1,0} sorts descending
c++ sort
#include<bits/stdc++.h>
vector<int> v = { 6,1,4,5,2,3,0};
sort(v.begin() , v.end()); // {0,1,2,3,4,5,6} sorts ascending
sort(v.begin(), v.end(), greater<int>()); // {6,5,4,3,2,1,0} sorts descending
how to sort array in c++
#include <iostream>
using namespace std;
int main () {
int n,i,j,temp;
cout << "how many Arrays you wanna sort? ";
cin >> n;
cout << endl << endl;
int a[n];
for(i = 0;i < n; i++){
cout << "please enter your " << i + 1 << " array : ";
cin >> a[i];
}
for(i = 0; i < n; i++){
for(j = 0; j < n - 1; j++){
if( a[j] > a[j+1]){
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
cout << "nArray after sorting using default sort is : n";
for (i = 0; i < n; i++)
cout << a[i] << 't';
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us