FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm-examples/cpp-algorithm/src/tree/tree_symmetric.h at main · codejsha/algorithm-examples · GitHub
codejsha
/
algorithm-examples
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm-examples
/
cpp-algorithm
/
src
/
tree
/
tree_symmetric.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (45 loc) · 1.37 KB
Breadcrumbs
algorithm-examples
/
cpp-algorithm
/
src
/
tree
/
tree_symmetric.h
Copy path
File metadata and controls
53 lines (45 loc) · 1.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
ifndef
CPP_ALGORITHM_TREE_SYMMETRIC_H
#
define
CPP_ALGORITHM_TREE_SYMMETRIC_H
#
include
"
binary_tree.h
"
namespace
TreeSymmetric
{
/*
*
* \brief Whether the binary tree is symmetric or not.
* \param tree the root of the tree
* \return whether the tree is symmetric
*/
bool
IsSymmetric
(
const
BinaryTree::Node<
int
>* tree);
/*
*
* \brief Check whether a binary tree is symmetric.
* \param left the left subtree of the tree
* \param right the right subtree of the tree
* \return whether the tree is symmetric
*/
bool
CheckSymmetric
(
const
BinaryTree::Node<
int
>* left,
const
BinaryTree::Node<
int
>* right);
}
//
----------------------------------------------------------------------------
inline
bool
TreeSymmetric::IsSymmetric
(
const
BinaryTree::Node<
int
>* tree)
{
return
tree ==
nullptr
||
CheckSymmetric
(tree->
left
, tree->
right
);
}
//
----------------------------------------------------------------------------
inline
bool
TreeSymmetric::CheckSymmetric
(
const
BinaryTree::Node<
int
>* left,
const
BinaryTree::Node<
int
>* right)
{
if
(left ==
nullptr
|| right ==
nullptr
)
{
return
left == right;
}
if
(left->
key
!= right->
key
)
{
return
false
;
}
return
CheckSymmetric
(left->
left
, right->
right
)
&&
CheckSymmetric
(left->
right
, right->
left
);
}
#
endif
Back
|
FazBrowse Home
|
New Git URL