Sorting Network Verify and Draw
Check Whether Comparator Networks Sort and Draw Them
Src
TernaryGrayCode.cpp
Go to the documentation of this file.
1
3
4
#include "
TernaryGrayCode.h
"
5
6
CTernaryGrayCode::~CTernaryGrayCode
(){
7
delete
[]
m_nDirection
;
8
}
//destructor
9
13
14
void
CTernaryGrayCode::Initialize
(
const
UINT n){
15
CBinaryGrayCode::Initialize
(n);
//reset as for the binary version
16
17
delete
[]
m_nDirection
;
18
m_nDirection
=
new
int
[
m_nSize
+ 3];
19
20
for
(UINT i=0; i<
m_nSize
+3; i++)
//reset the direction array too
21
m_nDirection
[i] = 0;
22
}
//Initialize
23
28
29
UINT
CTernaryGrayCode::Next
(){
30
UINT i =
m_nGrayCodeStack
[0];
31
m_nGrayCodeStack
[0] = 1;
32
UINT j = 2*i -
m_nGrayCodeWord
[2*i -
m_nDirection
[i]];
33
m_nGrayCodeWord
[j] ^= 1;
34
35
if
(
m_nGrayCodeWord
[2*i] ==
m_nGrayCodeWord
[2*i - 1]){
36
m_nDirection
[i] ^= 1;
37
m_nGrayCodeStack
[i-1] =
m_nGrayCodeStack
[i];
38
m_nGrayCodeStack
[i] = i + 1;
39
}
//if
40
41
m_nZeros
+= 1 - 2*
m_nGrayCodeWord
[j];
42
43
return
j;
44
}
//Next
TernaryGrayCode.h
Interface for the ternary reflected Gray code generator class CTernaryGrayCode.
CBinaryGrayCode::Initialize
virtual void Initialize(const UINT)
Get first code word.
Definition:
BinaryGrayCode.cpp:39
CBinaryGrayCode::m_nGrayCodeWord
UINT * m_nGrayCodeWord
Current code word.
Definition:
BinaryGrayCode.h:70
CBinaryGrayCode::m_nGrayCodeStack
UINT * m_nGrayCodeStack
Stack to remove recursion.
Definition:
BinaryGrayCode.h:71
CBinaryGrayCode::m_nZeros
UINT m_nZeros
Number of zeros in the code word.
Definition:
BinaryGrayCode.h:68
CBinaryGrayCode::m_nSize
UINT m_nSize
Size of the code word.
Definition:
BinaryGrayCode.h:69
CTernaryGrayCode::Next
UINT Next()
Get next code word.
Definition:
TernaryGrayCode.cpp:29
CTernaryGrayCode::m_nDirection
int * m_nDirection
Direction of ternary change.
Definition:
TernaryGrayCode.h:70
CTernaryGrayCode::~CTernaryGrayCode
~CTernaryGrayCode()
Destructor.
Definition:
TernaryGrayCode.cpp:6
CTernaryGrayCode::Initialize
void Initialize(const UINT)
Get first code word.
Definition:
TernaryGrayCode.cpp:14
Generated on Mon May 15 2023 11:38:34 for Sorting Network Verify and Draw by
1.9.4