Created
June 22, 2012 08:56
-
-
Save obstschale/2971468 to your computer and use it in GitHub Desktop.
Print a binary tree
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 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 ); | |
/* ... */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's useless.