-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBST.h
53 lines (44 loc) · 1.43 KB
/
BST.h
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
/* header file for BST implementation */
/*Author:Xingxing Geng, 2/17/2018*/
/*this BST has 5 main methods: search,insert,remove,sort,rangeSearch*/
#ifndef BST_H
#define BST_H
#include <iostream>
#include <fstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
class BST{
public:
BST();
~BST();
bool search(std::string & x);
void insert(std::string & x);
void remove(std::string & x);
vector<std::string> sort();//what return type should sort method be ?
void rangeSearch(std::string a, std::string b);// we do not know which is greater , need to consdier when implement
private:
struct Node{
Node* left;
Node* right;
std::pair<std::string, int> key;
/* from book do we need intialize list*/
// Node(string ele):key(ele,1),left(0),right(0){}
Node(std::string ele , Node* lt, Node* rt){
key = make_pair(ele,1);
left = lt;
right = rt;
}
};
Node *root;
int size;//number of node , used for sort method
bool search(std::string & x, Node* t);
void insert(std::string & x, Node* & t);
void remove(std::string & x, Node* & t);
void sort(vector<string> v, Node* t);
void rangeSearch(std::string a, std::string b,Node* t);
void makeEmpty(Node* &t);
Node* clone(Node* t);
};
#endif