Sort random number : sort « STL Algorithms Sorting « C++






Sort random number

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

const int N = 5;

int main()
{
   int    d[N], i, *e = d + N;

   for (i = 0; i < N; ++i){
      d[i] = rand();
   }   

   sort(d, e);

   for (i = 0; i < N; ++i){
      cout << d[i];
   }   
}
  
    
  








Related examples in the same category

1.Using an in-place generic sort algorithm
2.Sort a vector and print out the sorted elements
3.Sort all element in an array
4.Sort part of the elements in an array
5.Sort a vector into ascending order of id members
6.Sort elements in deque
7.Sort elements reversely with custom function
8.Using the generic sort algorithm with a binary predicate: greater
9.Use custom function and sort to sort strings by length
10.Sorting user-defined class
11.Sort the entire container
12.Sort into descending order by using greater
13.Sort a subset of the container
14.Sort a string array with sort()