-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntBinaryTree.h
More file actions
99 lines (82 loc) · 2.48 KB
/
IntBinaryTree.h
File metadata and controls
99 lines (82 loc) · 2.48 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
// Specification file for the IntBinaryTree class
// (Adapted from the IntBinaryTree class in Chapter 20
// of the Gaddis textbook.)
// Portions copyright 2012, Pearson Education, Inc.
//
#ifndef INTBINARYTREE_H
#define INTBINARYTREE_H
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
class IntBinaryTree
{
private:
struct TreeNode
{
int value; // The value in the node
TreeNode *left; // Pointer to left child node
TreeNode *right; // Pointer to right child node
};
static bool verboseMode;
TreeNode *root; // Pointer to the root node
string inputFileName;
fstream inputFile;
// Private member functions
void insert(TreeNode *&nodePtr, TreeNode *&newNode);
void destroySubTree(TreeNode *&);
void deleteNode(int, TreeNode *&);
void makeDeletion(TreeNode *&);
void displayInOrder(TreeNode *) const;
void displayPreOrder(TreeNode *) const;
void displayPostOrder(TreeNode *) const;
void displayNode(TreeNode *) const;
void IntBinaryTree::displayNode(TreeNode *, int) const;
int calculateNumberOfNodes(TreeNode *nodePtr) const;
int calculateSubTreeHeight(TreeNode *nodePtr) const;
void enhancedTreeDisplay(TreeNode *, int) const;
public:
// Constructor
IntBinaryTree()
{
root = NULL;
}
// Destructor
~IntBinaryTree()
{ destroySubTree(root); }
// Binary tree operations
TreeNode *getRoot()
{ return root; }
void setRoot(TreeNode *newRoot)
{ root = newRoot; }
void insertNode(int);
bool searchNode(int);
void remove(int);
void userInsertNode();
void userSearchNode();
void userRemoveNode();
void userRemoveAllNodes();
void displayInOrder() const
{ displayInOrder(root); }
void displayPreOrder() const
{ displayPreOrder(root); }
void displayPostOrder() const
{ displayPostOrder(root); }
void enhancedTreeDisplay() const;
void displayNumberOfNodes() const;
void displayTreeHeight() const;
static void setVerboseMode(bool param)
{
verboseMode = param;
}
static bool getVerboseMode()
{ return verboseMode; }
string getInputFileName()
{ return inputFileName; }
bool openInputFile();
void closeInputFile();
bool readDataLine(string &recordText);
int readFile();
};
#endif