-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.cpp
More file actions
94 lines (90 loc) · 2.28 KB
/
driver.cpp
File metadata and controls
94 lines (90 loc) · 2.28 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <iomanip>
#include "Structure.h"
#include "random_op.h"
main()
{
//creates structure pointer
Structure< int > *a;
//random seed
unsigned int seed;
//number of opearions and range
int numop, range;
int key;
//to switch
char rand_op;
//int data pointer
int *data;
//recording number of operations
int g, d, u;
int q;
//allocating spaces
a = new Structure< int >();
data = new int;
//getting user inputs
cout << "Please indicate a range: " << endl;
cin >> range;
cout << "Please indicate number of operations: " << endl;
cin >> numop;
cout << "Please indicate seed: " << endl;
cin >> seed;
cout << "------------------------------" << endl;
//creates random operator
Random_operation Rand_op( seed, range);
//initialization
g = 0;
d = 0;
u = 0;
for ( q = 1; q <= numop; q++)
{
//cout << "Operation: "<< q << endl;
//randomizes
Rand_op.Randomize_next_op();
key = Rand_op.Get_key();
switch (Rand_op.Get_op())
{
case 'G':
//getter
data = a->MLH_get(key);
g++;
break;
case 'D':
//deleting
data = a->MLH_delete(key);
d++;
//in case of memory leak
data = NULL;
break;
case 'I':
data = new int;
*data = q;
//insertion
a->MLH_insert(key, data);
u++;
break;
}
if (q % (numop/10) == 0 )
{
//prints 10 times
if ( range > 100 ) {
a->MLH_set_print_option(1);
} else {
//prints every node
a->MLH_set_print_option(0);
}
//prints entire structure
cout << *a;
}
}
//summary
cout << "Update: " << u << " times" <<endl;
cout << "Delete: " << d << " times" <<endl;
cout << "Get " << g << " times" <<endl;
cout << "Counter is " << a->getcounter() << endl;
//frees memory
delete a;
a = NULL;
}