forked from yuanzoudetuzi/binaryTree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryTree.h
More file actions
executable file
·61 lines (46 loc) · 1.69 KB
/
BinaryTree.h
File metadata and controls
executable file
·61 lines (46 loc) · 1.69 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
//
// Created by Administrator on 2017/4/6.
//
#ifndef BINARYTREE_BINARYTREE_H_H
#define BINARYTREE_BINARYTREE_H_H
#include <iostream>
template< typename T = int>
class BinaryTree {
public:
BinaryTree () = default;
BinaryTree ( const BinaryTree &bt);
BinaryTree ( const T &theElement);
~BinaryTree();
void insert ( const T &theElement );
void remove ( const T &theElement );
void makeEmpty ();
bool isFind ( const T &theElement ) const;
void preOrder () const;
void inOrder () const;
void postOrder () const;
private:
struct BinaryNode {
T element;
BinaryNode *leftNode;
BinaryNode *rightNode;
BinaryNode (const T &ele, BinaryNode *left, BinaryNode *right)
: element(ele), leftNode(left), rightNode(right) {};
BinaryNode (const T &ele)
: element(ele), leftNode(nullptr), rightNode(nullptr) {};
BinaryNode (const BinaryNode *bNode)
: element(bNode->element), leftNode(bNode->leftNode), rightNode(bNode->rightNode){
}
};
BinaryNode *root;
BinaryNode * clone (const BinaryNode *bNode ) ;
void insert ( const T &theElement, BinaryNode * &t );
void remove ( const T &theElement, BinaryNode * &t );
void makeEmpty (BinaryNode * &t );
bool isFind ( const T &theElement, BinaryNode *t ) const;
BinaryNode * findMin (BinaryNode *bNode) const;
BinaryNode * findMax (BinaryNode *bNode) const;
void preOrder ( BinaryNode *bNode ) const;
void inOrder ( BinaryNode *bNode ) const;
void postOrder (BinaryNode *bNode ) const;
};
#endif //BINARYTREE_BINARYTREE_H_H