-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
76 lines (66 loc) · 1.75 KB
/
test.cpp
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
#include <iostream>
using namespace std;
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <stdio.h>
#include <fstream>
#include "SplayTreeHeader.h"
void show_Node(Node* n);
//To get operation execution time.
double performancecounter_diff(LARGE_INTEGER *a, LARGE_INTEGER *b);
int main() {
SplayTree s = SplayTree();
LARGE_INTEGER start, end;
double tiempo;
srand(time(NULL));
//We print the result in result.dat.
ofstream nf("result.dat");
int m, n;
for (int i = 0; i < 50000; i++) {
m = rand() % 3;
n = rand() % 50000;
if (m == 0) {
//Insert
QueryPerformanceCounter(&start);
s.insert(n);
QueryPerformanceCounter(&end);
nf << i << " " << performancecounter_diff(&end, &start) * 1000 << endl;
}
else if (m == 1) {
//Search
QueryPerformanceCounter(&start);
s.search(n);
QueryPerformanceCounter(&end);
nf << i << " " << performancecounter_diff(&end, &start) * 1000 << endl;
}
else {
//Remove
QueryPerformanceCounter(&start);
s.remove(n);
QueryPerformanceCounter(&end);
nf << i << " " << performancecounter_diff(&end, &start) * 1000 << endl;
}
}
return 0;
}
double performancecounter_diff(LARGE_INTEGER *a, LARGE_INTEGER *b) {
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
return (double)(a->QuadPart - b->QuadPart) / (double)freq.QuadPart;
}
void show_Node(Node* n) {
if (n != NULL) {
if (n->father != NULL) {
cout << n->value << " with father with value " << n->father->value << endl;
}
if (n->rightSon != NULL) {
cout << n->value << " with right son with value " << n->rightSon->value << endl;
show_Node(n->rightSon);
}
if (n->leftSon != NULL) {
cout << n->value << " with left son with value " << n->leftSon->value << endl;
show_Node(n->leftSon);
}
}
}