fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. class Compare
  8. {
  9. public:
  10.  
  11. static int num;
  12.  
  13. Compare()
  14. {
  15. num++;
  16. }
  17.  
  18. Compare(const Compare& compare)
  19. {
  20. num++;
  21. }
  22.  
  23. ~Compare()
  24. {
  25. }
  26.  
  27. bool operator() (int v1, int v2)
  28. {
  29. return v1 < v2;
  30. }
  31. };
  32. int Compare::num = 0;
  33.  
  34. int main()
  35. {
  36. vector<int> mas;
  37.  
  38. int size = 10000000;
  39. for( int k = 1; k <= size; k++ )
  40. {
  41. mas.push_back( rand() );
  42. }
  43.  
  44. sort( mas.begin(), mas.end(), Compare() );
  45.  
  46. float rate = (float)Compare::num/(float)size;
  47.  
  48. cout<<"rate="<<rate<<endl;
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 1.45s 3476KB
stdin
Standard input is empty
stdout
rate=1.45666