-
Notifications
You must be signed in to change notification settings - Fork 45
/
display.cpp
67 lines (55 loc) · 1.5 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
#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) return;
queue<Node*> q;
q.push(cursor);
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) {
Node* firstLeft = firstLeftNode(cursor);
if (firstLeft == NULL) {
cout << "No Data in the Database yet!" << endl;
return;
}
while (firstLeft != NULL) {
for (int i = 0; i < firstLeft->keys.size(); i++) {
cout << firstLeft->keys[i] << " ";
}
firstLeft = firstLeft->ptr2next;
}
cout << endl;
}
#endif