Skip to content

Instantly share code, notes, and snippets.

@Rhomboid
Created December 18, 2013 09:35
Show Gist options
  • Select an option

  • Save Rhomboid/8019668 to your computer and use it in GitHub Desktop.

Select an option

Save Rhomboid/8019668 to your computer and use it in GitHub Desktop.
Recursive stack blowout demonstration
#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