-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_client_4.cpp
More file actions
153 lines (111 loc) · 4 KB
/
demo_client_4.cpp
File metadata and controls
153 lines (111 loc) · 4 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "demo_final_2.cpp"
// #include "test2_m.cpp"
#include <iostream>
#include <string>
using namespace std;
bool IsOdd (int i)
{
return ((i%2)==1);
}
bool IsEven (int i)
{
return ((i%2)==0);
}
int main()
{
// Iterators
// Algorithms
cout<<"\n--------------------------------------------------------------------------------------------------------------------------------\n\n";
srand(16);
Treap_t<int> t_1;
t_1.insert(19);
t_1.insert(23);
t_1.insert(5);
t_1.insert(1);
t_1.insert(90);
t_1.insert(28);
t_1.insert(55);
t_1.insert(82);
t_1.insert(100);
t_1.insert(9);
Treap_t<double> t_2;
t_2.insert(1.5);
t_2.insert(83.972);
t_2.insert(5.0);
t_2.insert(12.28);
t_2.insert(59.08);
t_2.insert(3.14);
t_2.insert(99.99);
Treap_t<string> t_3;
t_3.insert("D");
t_3.insert("B");
t_3.insert("G");
t_3.insert("A");
t_3.insert("P");
t_3.insert("Q");
t_3.insert("T");
vector<int> v_1 = {9, 82, 158, 1912, 174, 242, 99, 108, 235, 911, 100, 102, 555};
Treap_t<int> t_4(v_1.begin(), v_1.end());
Treap_t<int> t_5;
t_5.union_treaps(&t_1, &t_4);
Treap_t<int> t_6;
t_6.intersect_treaps(&t_1, &t_4);
cout<<"Tree T_1:\n\n"<<t_1<<"\n";
cout<<"\n--------------------------------------------------------------------------------------------------------------------------------\n\n";
cout<<"Tree T_3:\n\n"<<t_3<<"\n";
cout<<"\n--------------------------------------------------------------------------------------------------------------------------------\n\n";
cout<<"Generic Find\n\n";
Treap_t<int>::Iterator it_1 = find(t_1.begin(), t_1.end(), 23);
if(it_1 != t_1.end())
{
cout << "Key " << *it_1 << " found in T_1" << "\n\n";
}
else
{
cout << "Key " << 23 << " not found in T_1" << "\n\n";
}
Treap_t<int>::Iterator it_2 = find(t_1.begin(), t_1.end(), 364);
if(it_2 != t_1.end())
{
cout << "Found key " << *it_2 << " in T_1" << "\n\n";
}
else
{
cout << "Key " << 364 << " not found in T_1" << "\n\n";
}
cout<<"\n--------------------------------------------------------------------------------------------------------------------------------\n\n";
cout<<"Member Find\n\n";
Treap_t<int>::Iterator it_3 = t_1.find(t_1.begin(), t_1.end(), 23);
if(it_3 != t_1.end())
{
cout << "Found key " << *it_3 << " in T_1" << "\n\n";
}
else
{
cout << "Key " << 23 << " not found in T_1" << "\n\n";
}
cout<<"\n--------------------------------------------------------------------------------------------------------------------------------\n\n";
cout<<"Generic Find_if\n\n";
Treap_t<int>::Iterator it_4 = find_if(t_1.begin(), t_1.end(), IsEven);
if(it_4 != t_1.end())
{
cout << "Found Even key " << *it_4 << " in T_1" << "\n\n";
}
else
{
cout << "Even Key not found in T_1" << "\n\n";
}
cout<<"\n--------------------------------------------------------------------------------------------------------------------------------\n\n";
cout<<"Member Replace\n\n";
t_3.replace(t_3.begin(), t_3.end(), "B", "H");
t_3.replace(t_3.begin(), t_3.end(), "D", "F");
t_3.replace(t_3.begin(), t_3.end(), "Y", "K");
cout<<"T_3 after replacing B with H and D with F and trying to replace a non existent key Y with K\n" << t_3 << "\n\n";
cout<<"\n--------------------------------------------------------------------------------------------------------------------------------\n\n";
cout<<"Generic Count and Count_if\n\n";
int c_1 = count(t_1.begin(), t_1.end(), 5);
cout<<"Count of key " << 5 << " in T_1: " << c_1 << "\n\n";
int c_2 = count_if(t_1.begin(), t_1.end(), IsOdd);
cout<<"Count of Odd keys" << " in T_1 : " << c_2 << "\n\n";
cout<<"\n--------------------------------------------------------------------------------------------------------------------------------\n\n";
}