Skip to content

Instantly share code, notes, and snippets.

@obstschale
Created June 22, 2012 08:56
Show Gist options
  • Save obstschale/2971468 to your computer and use it in GitHub Desktop.
Save obstschale/2971468 to your computer and use it in GitHub Desktop.
Print a binary tree
void padding ( char ch, int n ){
int i;
for ( i = 0; i < n; i++ )
putchar ( ch );
}
void structure ( struct node *root, int level ){
int i;
if ( root == NULL ) {
padding ( '\t', level );
puts ( "~" );
} else {
structure ( root->right, level + 1 );
padding ( '\t', level );
printf ( "%d\n", root->info );
structure ( root->left, level + 1 );
}
}
int main ( void ){
struct node *tree = NULL;
/* ... */
structure ( tree, 0 );
/* ... */
}
@obstschale
Copy link
Author

90 degree rotation, I use this for printing the structure of a tree because it's fast and easy:

@adamijak
Copy link

adamijak commented Oct 30, 2019

void structure ( struct node *root, int level ){ int i;
what does int i; stand for?

@obstschale
Copy link
Author

To be honest, I have no idea. This is over 7 years old ^^
But it seems i is declared but not used in this function.

@adamijak
Copy link

adamijak commented Oct 30, 2019 via email

@shivanshu-semwal
Copy link

void structure ( struct node *root, int level ){ int i;
what does int i; stand for?

It's useless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment