Глава 19. Классы-шаблоны_______________________________523
16: ( |
17: swapAt ° j; |
18: for( unsigned long k=j+l; k<elem; k++) |
19: if( IsGreater( data[swapAt], data[k])) |
20: swapAt = k; // запомним точку перестановки |
21: |
22: Swap( data[j], data[swapAt]); // переставим уже после |
// всех сравнений |
23: ) |
24: } |
25: #ifdef SORTSSCAFFOLD |
26: • #include <iostream.h> |
27: #include <dos.h> |
28: #include <stdio.h> |
29: class TIMER : public time |
30: ( |
31: public: |
32: TIMER()( gettime( this); } |
33: «pragma warn -inl |
34: friend ostreams operator«( ostreams os, TIMERS t) * |
35: { |
36: static char buf [9]; |
37: sprintf( buf, "%0.2d:%0.2d:%0.2d", |
38: t.tihour, t.timin, t.tisec); |
39: return os « buf; |
40: ) |
41: ); |
42: void main() |
43: { |
44: int d[100]; |
45: for( int j = 99; j >= 0; j—) |
46: d[j] » j; |
47: TIMER start; |
48: GumSortf d, SIZEOP( d)); |
49: TIMER Stop; |
50: cout « "start - "« start « endl |
51: « "stop — "« stop « endl; |
52: fort int j = 0; j<100; j++) |
53: cout « d[j] « ", "; |
54: char* words[] » { "Winkie", "Willy", "Wee" ); |
55: SelectionSort( words, 3); |
56: cout « endl « words[0] « endl |
57: « words[1] « endl |
58: « words[2] « endl; |
59: } , |
60: #endif |
Здесь есть, что обсудить. В строках с 4 по 24 определены функции-шаблоны |
двух рассмотренных алгоритмов сортировки. Строки с 25 по 60 содержат |
испытательный стенд. |