-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashTree.h
86 lines (70 loc) · 1.79 KB
/
hashTree.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
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
//
// hashTree.h
// Lab4.Rodman.260
//
// Created by Nathan Rodman on 5/31/14.
// Copyright (c) 2014 nathan.rodman. All rights reserved.
//
#ifndef Lab4_Rodman_260_hashTree_h
#define Lab4_Rodman_260_hashTree_h
#include "data.h"
struct treeNode
{
data * item;
treeNode *left, *right;
treeNode(data * aData)
{
item = aData;
left = nullptr;
right = nullptr;
}
};
struct hashNode
{
data * item;
hashNode * next;
/* hashNode(const data& aData)
{
*item = aData;
next = nullptr;
}
*/
};
class hashTree
{
public:
hashTree();
hashTree(const char * fileName);
hashTree(const hashTree & aHashTree);
~hashTree();
const hashTree& operator=(hashTree & aCollection);
void add(const data & aData);
bool retrieve(char * key, data & aData);
bool retrieve(char * productType, int & index);
bool remove(char * vendorName);
void displayByType();
void displayByName();
void displayProducts(int index);
void writeOut(const char * fileName);
private:
treeNode * root; //the bst
hashNode ** table; //the hash table
void addToTree(data * ptrItem);
void addToTable(data * ptrItem);
void removeFromTree(char * name);
bool removeFromTable(char * name);
int calculateIndex(char * key) const;
int capacity = 11;
int size;
void initializeTable();
//Recursive functions for BST
void insert(treeNode*& root, data& aData);
bool retrieve(treeNode * root, char * key, data& aData) const;
bool remove(treeNode*& root, char * key);
void deleteNode(treeNode *& target);
void display(treeNode * root) const;
void destroyTable(treeNode*& root);
void copyTable(treeNode*& newRoot, treeNode * root);
void writeOut(ofstream & out, treeNode * root);
};
#endif