c++ algorithm library sort code example
Example 1: c++ sort
int arr[]= {2,3,5,6,1,2,3,6,10,100,200,0,-10};
int n = sizeof(arr)/sizeof(int);
sort(arr,arr+n);
for(int i: arr)
{
cout << i << " ";
}
Example 2: sorting algorithm c++
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int numb[7];
int i, j;
for(i=0;i<=6;i++)
{
cout << "Enter a number" << endl;
cin >> numb[i];
}
for (i=0;i<=5;i++)
{
for (j=i+1;j<=5;j++)
{
int temp;
if (numb[i] > numb[j])
{
temp = numb[i];
numb[i] = numb[j];
numb[j] = temp;
}
}
}
for (i=0;i<=6;i++)
{
cout << endl << numb[i] << endl;
}
}