-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSort.cpp
More file actions
65 lines (49 loc) · 1.59 KB
/
TestSort.cpp
File metadata and controls
65 lines (49 loc) · 1.59 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
#include <iostream.h>
#include "Sort.h"
#include "vector.h"
#include "Random.h"
void checkSort( const vector<int> & a )
{
for( int i = 0; i < a.size( ); i++ )
if( a[ i ] != i )
cout << "Error at " << i << endl;
cout << "Finished checksort" << endl;
}
void permute( vector<int> & a )
{
static Random r;
for( int j = 1; j < a.size( ); j++ )
swap( a[ j ], a[ r.randomInt( 0, j ) ] );
}
int main( )
{
const int NUM_ITEMS = 1000;
vector<int> a( NUM_ITEMS );
for( int i = 0; i < a.size( ); i++ )
a[ i ] = i;
for( int theSeed = 0; theSeed < 20; theSeed++ )
{
permute( a );
insertionSort( a );
checkSort( a );
permute( a );
heapsort( a );
checkSort( a );
permute( a );
shellsort( a );
checkSort( a );
permute( a );
mergeSort( a );
checkSort( a );
permute( a );
quicksort( a );
checkSort( a );
permute( a );
largeObjectSort( a );
checkSort( a );
permute( a );
quickSelect( a, NUM_ITEMS / 2 );
cout << a[ NUM_ITEMS / 2 - 1 ] << " " << NUM_ITEMS / 2 << endl;
}
return 0;
}