-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd_sort.cpp
More file actions
67 lines (51 loc) · 1.23 KB
/
std_sort.cpp
File metadata and controls
67 lines (51 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* =====================================================================================
*
* Filename: sort.cpp
*
* Description:
*
* Version: 1.0
* Created: 2015年08月26日 17时14分19秒
* Last Modified: 2018-03-22 15:20:19
* Revision: none
* Compiler: gcc
*
* Author: zt (),
* Organization:
*
* =====================================================================================
*/
#include <iostream>
#include <algorithm>
#include <vector>
int main ( int argc, char* argv[] )
{
( void ) argc;
( void ) argv;
std::vector<int> veca;
for ( int i = 0; i < 0x100; ++i )
veca.push_back ( random() % 0xfff );
for ( unsigned int i = 0; i < veca.size(); ++i )
{
if ( ( i != 0 ) && ( i % 0x10 == 0 ) )
printf ( "\n" );
printf ( "0x%04x ", veca[i] );
}
printf ( "\n" );
printf ( "\n" );
std::sort ( veca.begin(), veca.end() );
for ( int i = 0; i < ( int ) veca.size(); ++i )
{
if ( ( i != 0 ) && ( i % 0x10 == 0 ) )
printf ( "\n" );
printf ( "0x%04x ", veca[i] );
}
printf ( "\n" );
double avg = 0;
for ( auto ele : veca )
avg += ele;
avg /= veca.size();
printf ( "avg = %f\n", avg );
return 0;
}