Sort in C++ Standard Template Library (STL)

Sorting is one of the most basic functions applied on data.
The prototype for sort is :

sort(startaddress, endaddress)
#include <iostream>
#include <algorithm>
using namespace std;
void show(int a[])
{
    for(int i = 0; i < 10; ++i)
        cout << '\t' << a[i];
}
int main()
{
    int a[10]= {1, 5, 8, 9, 6, 7, 3, 4, 2, 0};
    cout << "\n The array before sorting is : ";
    show(a);
    sort(a, a+10);
    cout << "\n\n The array after sorting is : ";
    show(a);
    return 0;
}

The outut of the above program is :

The array before sorting is : 	1	5	8	
9	6	7	3	4	2	0

 The array after sorting is : 	0	1	2	
3	4	5	6	7	8	9

Disclaimer: This does not belong to TechCodeBit, its an article taken from the below
source and credits.
source and credits: http://www.geeksforgeeks.org
We have built the accelerating growth-oriented website for budding engineers and aspiring job holders of technology companies such as Google, Facebook, and Amazon
If you would like to study our free courses you can join us at

http://www.techcodebit.com. #techcodebit #google #microsoft #facebook #interview portal #jobplacements
#technicalguide

rakesh

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar