Created
December 18, 2013 09:35
-
-
Save Rhomboid/8019668 to your computer and use it in GitHub Desktop.
Recursive stack blowout demonstration
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
| #include <stdio.h> | |
| #include <stdbool.h> | |
| struct node { | |
| void *val; | |
| struct node *left, *right; | |
| }; | |
| void in_order_traverse(const struct node *n, void (*callback)(const void *), size_t depth) | |
| { | |
| printf("%zu\n", depth); | |
| if(n->left) | |
| in_order_traverse(n->left, callback, depth + 1); | |
| callback(n->val); | |
| if(n->right) | |
| in_order_traverse(n->right, callback, depth + 1); | |
| } | |
| void dummy_callback(const void *val) { } | |
| int main() | |
| { | |
| struct node tree[2] = {0}; | |
| tree[0].left = &tree[1]; | |
| tree[1].left = &tree[0]; | |
| in_order_traverse(tree, dummy_callback, 1); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment