-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
44 lines (29 loc) · 733 Bytes
/
main.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
#include "avl.h"
#include <fstream>
#include <sstream>
template<typename K, typename I>
void readFileNodes(AVL<K,I>& bt, std::string filename);
int main(){
AVL<int,std::string> bt;
readFileNodes(bt, "../names.txt");
std::cout << bt << std::endl;
bt.displayTree();
return 0;
}
template<typename K, typename I>
void readFileNodes(AVL<K,I>& bt, std::string filename){
std::string line, key, item;
std::ifstream file (filename);
if (file.is_open()){
while ( getline (file,line) ){
std::istringstream iss(line);
iss >> key;
iss >> item;
bt.insert(std::stoi(key), item);
}
file.close();
}
else{
std::cout << "Unable to open file." << std::endl;
}
}