Last active
August 17, 2023 23:59
-
-
Save assyrianic/1f5887a6563a17b768d5e80125c9920d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum{ TREE_DATA = 3 }; | |
enum{ TREE_SIZE = 2 << TREE_DATA }; | |
/// 0 is root node | |
/// odd numbers above 0 are left nodes. | |
/// even numbers above 0 are right nodes. | |
enum struct ArrayTree { | |
int data[TREE_SIZE]; | |
/// -1 0 1 | |
int IndexType(int i) { | |
if( i==0 ) { | |
return i; | |
} else if( index & 1 ) { | |
return -1; | |
} | |
return 1; | |
} | |
int GetRightChild(int i) { | |
return (2*i) + 2; | |
} | |
int GetLeftChild(int i) { | |
return (2*i) + 1; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment