Sorting Network Verify and Draw
Check Whether Comparator Networks Sort and Draw Them
TernaryGrayCode.cpp
Go to the documentation of this file.
1
3
4#include "TernaryGrayCode.h"
5
7 delete [] m_nDirection;
8} //destructor
9
13
14void 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
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;
38 m_nGrayCodeStack[i] = i + 1;
39 } //if
40
41 m_nZeros += 1 - 2*m_nGrayCodeWord[j];
42
43 return j;
44} //Next
Interface for the ternary reflected Gray code generator class CTernaryGrayCode.
virtual void Initialize(const UINT)
Get first code word.
UINT * m_nGrayCodeWord
Current code word.
UINT * m_nGrayCodeStack
Stack to remove recursion.
UINT m_nZeros
Number of zeros in the code word.
UINT m_nSize
Size of the code word.
UINT Next()
Get next code word.
int * m_nDirection
Direction of ternary change.
~CTernaryGrayCode()
Destructor.
void Initialize(const UINT)
Get first code word.