-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB+ Tree.cpp
More file actions
112 lines (91 loc) · 2.85 KB
/
B+ Tree.cpp
File metadata and controls
112 lines (91 loc) · 2.85 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
//#include <filesystem>
#include "B+ Tree.h"
#define _CRT_SECURE_NO_DEPRECATE //for VS 2019
void insertionMethod(BPTree** bPTree) {
int rollNo;
int age, marks;
string name;
cout << "Please provide the rollNo: ";
cin >> rollNo;
cout << "\nWhat's the Name, Age and Marks acquired?: ";
cin >> name >> age >> marks;
string fileName = "DBFiles/";
fileName += to_string(rollNo) + ".txt";
FILE* filePtr = fopen(fileName.c_str(), "w");
string userTuple = name + " " + to_string(age) + " " + to_string(marks) + "\n";
fprintf(filePtr, userTuple.c_str());
//fclose(filePtr);
(*bPTree)->insert(rollNo, filePtr);
fclose(filePtr);
cout << "Insertion of roll No: " << rollNo << " Successful"<<endl;
}
void searchMethod(BPTree* bPTree) {
int rollNo;
cout << "What's the RollNo to Search? ";
cin >> rollNo;
bPTree->search(rollNo);
}
void printMethod(BPTree* bPTree) {
int opt;
cout << "Press \n\t1.Hierarical-Display \n\t2.Sequential-Display\n";
cin >> opt;
cout << "\nHere is your File Structure" << endl;
if (opt == 1)
bPTree->display(bPTree->getRoot());
else
bPTree->seqDisplay(bPTree->getRoot());
}
void deleteMethod(BPTree* bPTree) {
cout << "Showing you the Tree, Choose a key from here: " << endl;
bPTree->display(bPTree->getRoot());
int tmp;
cout << "Enter a key to delete: " << endl;
cin >> tmp;
bPTree->removeKey(tmp);
//Displaying
bPTree->display(bPTree->getRoot());
}
int main() {
/*
Please have a look at the default schema to get to know about the table
Reference - img/database.jpg
*/
cout << "\n***Welcome to DATABASE SERVER**\n"
<< endl;
bool flag = true;
int option;
int maxChildInt = 4, maxNodeLeaf = 3;
cout << "Please provide the value to limit maximum child Internal Nodes can have: ";
cin >> maxChildInt;
cout << "\nAnd Now Limit the value to limit maximum Nodes Leaf Nodes can have: ";
cin >> maxNodeLeaf;
BPTree* bPTree = new BPTree(maxChildInt, maxNodeLeaf);
do {
cout << "\nPlease provide the queries with respective keys : " << endl;
cout << "\tPress 1: Insertion \n\tPress 2: Search \n\tPress 3: Print Tree\n\tPress 4: Delete Key In Tree\n\tPress 5: ABORT!" << endl;
cin >> option;
switch (option) {
case 1:
insertionMethod(&bPTree);
break;
case 2:
searchMethod(bPTree);
break;
case 3:
printMethod(bPTree);
break;
case 4:
deleteMethod(bPTree);
break;
default:
flag = false;
break;
}
}while (flag);
return 0;
}