-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBSTApp.hpp
More file actions
101 lines (80 loc) · 1.99 KB
/
BSTApp.hpp
File metadata and controls
101 lines (80 loc) · 1.99 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
#ifndef BSTAPP_HPP
#define BSTAPP_HPP
#include "BST.hpp"
#include <iostream>
#include <string>
namespace BSTSpace
{
template<class K, class V>
class Dictionary
{
private:
BST<K,V> *data;
public:
Dictionary();
~Dictionary();
bool getValue(K key, V &value);
void setValue(K key, V value);
void insert(K key, V value);
void printAll();
};
template<class K, class V>
Dictionary<K,V>::Dictionary()
{
data = new BST<K,V>();
}
template<class K, class V>
Dictionary<K,V>::~Dictionary()
{
delete data;
}
template<class K,class V>
bool Dictionary<K,V>::getValue(K key, V &value)
{
return data->search(key, value);
}
template<class K,class V>
void Dictionary<K,V>::setValue(K key, V value)
{
data->insert(key, value);
}
template<class K, class V>
void Dictionary<K,V>::insert(K key, V value)
{
data->insert(key, value);
}
template<class K, class V>
void Dictionary<K, V>::printAll()
{
std::cout << "Dictionary Contents: ";
data->PrintTree();
}
void Demo()
{
Dictionary<int,std::string> StudentDict;
std::string name;
bool is_present;
StudentDict.insert(8, "Ameya");
StudentDict.insert(10, "Aami");
StudentDict.insert(25,"Medha");
StudentDict.insert(9,"Vishal");
StudentDict.insert(5,"Amritha");
StudentDict.insert(7,"Anjali");
std::cout << "Updating Roll 7..." << std::endl;
StudentDict.setValue(7, "Anjali Updated");
is_present = StudentDict.getValue(7, name);
std::cout << "Searching for Roll 7: ";
if (is_present == true)
std::cout << name << std::endl;
else
std::cout << "Roll Number not Present" << std::endl;
is_present = StudentDict.getValue(99, name);
std::cout << "Searching for Roll 99: ";
if (is_present == true)
std::cout << name << std::endl;
else
std::cout << "Roll Number not Present" << std::endl;
StudentDict.printAll();
}
}
#endif