Created
June 6, 2017 19:00
-
-
Save RdlP/8f0bfd4f14639f6af68fd7941b3c1776 to your computer and use it in GitHub Desktop.
This file contains 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
void print_tree_iterative(Node *root){ | |
Stack *nodes = (Stack*)malloc(sizeof(Stack)); | |
init_Stack(nodes); | |
push(nodes, root); | |
while (!empty(nodes)){ | |
Node * node = pop(nodes); | |
if (node->right){ | |
memcpy(node->right->code, node->code, node->depth); | |
node->right->code[node->depth] = 1; | |
push(nodes, node->right); | |
} | |
if (node->left){ | |
memcpy(node->left->code, node->code, node->depth); | |
node->left->code[node->depth] = 0; | |
push(nodes, node->left); | |
} | |
if (!node->left && !node->right){ | |
printf("0x%02X (%c): ", node->symbol, node->symbol); | |
printArr(node->code, node->depth); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment