Sort In C++
C++ STL provides a similar function
sort that sorts a vector or array (items with random access). sort() takes
a third parameter that is used to specify the order in which elements are to be
sorted.
Fig:Sort In C++ |
Program:
#include <iostream.h>
#include<conio.h>
void main()
{
int
arr[] = {1, 5, 8, 9, 6, 7, 3, 4, 2, 0};
int
n = sizeof(arr)/sizeof(arr[0]);
sort(arr,
arr+n);
cout
<< "\nArray after sorting using "
"default
sort is : \n";
for
(int i = 0; i < n; ++i)
cout
<< arr[i] << " ";
getch();
}
Output:
Array after sorting using default
sort is:
0,1,2,3,4,5,6,7,8,9
No comments:
Post a Comment