Skip to content

Instantly share code, notes, and snippets.

@assyrianic
Last active August 17, 2023 23:59
Show Gist options
  • Save assyrianic/1f5887a6563a17b768d5e80125c9920d to your computer and use it in GitHub Desktop.
Save assyrianic/1f5887a6563a17b768d5e80125c9920d to your computer and use it in GitHub Desktop.
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