Acoustic FDTD Solver
Main Page
Classes
Files
File List
File Members
include
Node.hpp
Go to the documentation of this file.
1
#ifndef NODE_HPP
2
#define NODE_HPP
3
4
#include <cstdlib>
5
6
class
Node
{
7
Node
*
left
;
8
Node
*
right
;
9
double
x
;
10
unsigned
short
idx
;
11
public
:
12
Node
() {
13
left
= NULL;
14
right
= NULL;
15
x
= 0;
16
idx
= 0;
17
}
18
Node
(
double
x
,
unsigned
short
idx
) {
19
this->x =
x
;
20
this->idx=
idx
;
21
left
= NULL;
22
right
= NULL;
23
}
24
Node
(
const
Node
&n) {
25
x
= n.
x
;
26
idx
= n.
idx
;
27
left
= n.
left
;
28
right
= n.
right
;
29
}
30
Node
&
operator=
(
const
Node
&n) {
31
x
= n.
x
;
32
idx
=n.
idx
;
33
left
= n.
left
;
34
right
= n.
right
;
35
return
*
this
;
36
}
37
bool
operator<
(
const
Node
&n)
const
{
38
return
x
< n.
x
;
39
}
40
bool
operator>
(
const
Node
&n)
const
{
41
return
x
> n.
x
;
42
}
43
bool
operator==
(
const
Node
&n)
const
{
44
return
x
== n.
x
;
45
}
46
unsigned
short
getIndex
()
const
{
47
return
idx
;
48
}
49
double
getValue
()
const
{
50
return
x
;
51
}
52
57
Node
setLeft
(
const
Node
&node) {
58
if
(
left
== NULL) {
59
left
=
new
Node
(node);
60
return
node;
61
}
else
{
62
if
(node==*
left
) {
63
return
*
left
;
64
}
65
if
(node < *
left
) {
66
return
left
->
setLeft
(node);
67
}
68
if
(*
left
< node) {
69
return
left
->
setRight
(node);
70
}
71
}
72
}
//setLeft()
73
78
Node
setRight
(
const
Node
&node) {
79
if
(
right
== NULL) {
80
right
=
new
Node
(node);
81
return
node;
82
}
else
{
83
84
if
(node == *
right
) {
85
return
*
right
;
86
}
87
if
(node < *
right
) {
88
return
right
->
setLeft
(node);
89
}
90
91
if
(*
right
< node) {
92
return
right
->
setRight
(node);
93
}
94
}
95
}
//setRight()
96
97
~Node
() {
98
if
(
left
!= NULL) {
99
delete
left
;
100
left
= NULL;
101
}
102
if
(
right
!= NULL) {
103
delete
right
;
104
right
= NULL;
105
}
106
}
107
};
108
109
#endif
Generated on Sun Jun 30 2013 00:04:08 for Acoustic FDTD Solver by
1.8.1.2