-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.cpp
82 lines (71 loc) · 1.8 KB
/
display.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
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
#include <iostream>
#include <queue>
#ifndef NODE_H
#include "B+ Tree.h"
void BPTree::display(Node* cursor) {
/*
Depth First Display
if (cursor != NULL) {
for (int i = 0; i < cursor->keys.size(); i++)
cout << cursor->keys[i] << " ";
cout << endl;
if (cursor->isLeaf != true) {
for (int i = 0; i < cursor->ptr2TreeOrData.ptr2Tree.size(); i++)
display(cursor->ptr2TreeOrData.ptr2Tree[i]);
}
}
*/
/*
Level Order Display
*/
if (cursor == NULL)
{
cout<<"No Data in the Database yet!\n";
return;
}
queue<Node*> q;
q.push(cursor);
if(q.empty())
{
cout<<"No Data in the Database yet!\n";
return;
};
cout << "\nHere is your File Structure" << endl;
while (!q.empty()) {
int sz = q.size();
for (int i = 0; i < sz; i++) {
Node* u = q.front(); q.pop();
//printing keys in self
for (int val : u->keys)
cout << val << " ";
cout << "|| ";//to seperate next adjacent nodes
if (u->isLeaf != true) {
for (Node* v : u->ptr2TreeOrData.ptr2Tree) {
q.push(v);
}
}
}
cout << endl;
}
}
void BPTree::seqDisplay(Node* cursor) {
if (cursor == NULL)
{
cout<<"No Data in the Database yet!\n";
return;
}
Node* firstLeft = firstLeftNode(cursor);
if (firstLeft == NULL) {
cout << "No Data in the Database yet!" << endl;
return;
}
cout << "\nHere is your File Structure" << endl;
while (firstLeft != NULL) {
for (int i = 0; i < firstLeft->keys.size(); i++) {
cout << firstLeft->keys[i] << " ";
}
firstLeft = firstLeft->ptr2next;
}
cout << endl;
}
#endif