C++ templates chapter 6(Using Templates in Practice)
2009-09-24 22:26
483 查看
tracertest.cpp
1 #include <iostream>
2 #include <algorithm>
3 #include "tracer.hpp"
4 using namespace std;
5
6 long SortTracer::n_created = 0;
7 long SortTracer::n_destroyed = 0;
8 long SortTracer::n_max_live = 0;
9 long SortTracer::n_assigned = 0;
10 long SortTracer::n_compared = 0;
11 int main()
12 {
13 // prepare sample input:
14 SortTracer input[]={7,3,5,6,4,2,0,1,9,8};
15
16 // print initial values:
17 for (int i=0; i<10; ++i) {
18 cerr << input[i].val() << ' ';
19 }
20 cerr << endl;
21
22 // remember initial conditions:
23 long created_at_start = SortTracer::creations();
24 long max_live_at_start = SortTracer::max_live();
25 long assigned_at_start = SortTracer::assignments();
26 long compared_at_start = SortTracer::comparisons();
27
28 // execute algorithm:
29 cerr << "---[ Start sort() ]--------------------\n";
30 sort<>(&input[0], &input[9]+1);
31 cerr << "---[ End sort() ]----------------------\n";
32
33 // verify result:
34 for (int i=0; i<10; ++i) {
35 cerr << input[i].val() << ' ';
36 }
37 cerr << "\n\n";
38
39 // final report:
40 cerr << "sort() of 10 SortTracer's"
41 << " was performed by:\n "
42 << SortTracer::creations() - created_at_start
43 << " temporary tracers\n "
44 << "up to "
45 << SortTracer::max_live()
46 << " tracers at the same time ("
47 << max_live_at_start << " before)\n "
48 << SortTracer::assignments() - assigned_at_start
49 << " assignments\n "
50 << SortTracer::comparisons() - compared_at_start
51 << " comparisons\n\n";
52
53 cin.get();
54 }
1 #include <iostream>
2 #include <algorithm>
3 #include "tracer.hpp"
4 using namespace std;
5
6 long SortTracer::n_created = 0;
7 long SortTracer::n_destroyed = 0;
8 long SortTracer::n_max_live = 0;
9 long SortTracer::n_assigned = 0;
10 long SortTracer::n_compared = 0;
11 int main()
12 {
13 // prepare sample input:
14 SortTracer input[]={7,3,5,6,4,2,0,1,9,8};
15
16 // print initial values:
17 for (int i=0; i<10; ++i) {
18 cerr << input[i].val() << ' ';
19 }
20 cerr << endl;
21
22 // remember initial conditions:
23 long created_at_start = SortTracer::creations();
24 long max_live_at_start = SortTracer::max_live();
25 long assigned_at_start = SortTracer::assignments();
26 long compared_at_start = SortTracer::comparisons();
27
28 // execute algorithm:
29 cerr << "---[ Start sort() ]--------------------\n";
30 sort<>(&input[0], &input[9]+1);
31 cerr << "---[ End sort() ]----------------------\n";
32
33 // verify result:
34 for (int i=0; i<10; ++i) {
35 cerr << input[i].val() << ' ';
36 }
37 cerr << "\n\n";
38
39 // final report:
40 cerr << "sort() of 10 SortTracer's"
41 << " was performed by:\n "
42 << SortTracer::creations() - created_at_start
43 << " temporary tracers\n "
44 << "up to "
45 << SortTracer::max_live()
46 << " tracers at the same time ("
47 << max_live_at_start << " before)\n "
48 << SortTracer::assignments() - assigned_at_start
49 << " assignments\n "
50 << SortTracer::comparisons() - compared_at_start
51 << " comparisons\n\n";
52
53 cin.get();
54 }
相关文章推荐
- Templates in depth(Chapter 3 of Thinking in C++ Vol 2)
- C++ templates chapter 8(Fundamentals in Depth)
- C++ templates chapter 9(Names in Templates)
- Using Dialog Templates to create an InputBox() in C++
- using dynamic library in c++
- [C++]Partly Specialize member function in Class Templates
- The C in C++(Chapter 3 of Thinking in C++)
- Binary Tree Inorder Traversal 二叉树的中序遍历(C++:Iterative solution using stack)
- [THINKING IN C++]CHAPTER 03:EXERCISE 03
- Vista Goodies in C++: Using Glass in Your UI
- Download file using libcurl in C/C++
- Using LAPACK in C/C++
- SQLite Practice Using C# in Windows
- Chapter 1. Why Object-Oriented Programming in C++
- Automating Excel 2007 and creating charts using C++ MFC application in Visual Studio 2008
- [Chapter 3 Process]Practice 3.2 Including the initial parent process, how many processes are created by the program shown in Figure?
- Using LAPACK in C/C++
- Summarizes chapter one of datastructures and program design in C++
- Using SQLite in C++ with Code::blocks
- How to get the password text in a text with password property from another process using C++ - 用C++如何从不同进程获取密码框文本