Created
May 10, 2016 00:15
-
-
Save jianminchen/f7742a123f3524c1d0fbd98e71c8f516 to your computer and use it in GitHub Desktop.
HackerRank - Tree - Tree Top view
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
/* | |
struct node | |
{ | |
int data; | |
node* left; | |
node* right; | |
}; | |
*/ | |
void top_viewL(node* root) | |
{ | |
if(root==NULL) | |
return; | |
top_viewL(root->left); | |
printf("%d ", root->data); | |
} | |
void top_viewR(node* root) | |
{ | |
if(root==NULL) | |
return; | |
printf("%d ", root->data); | |
top_viewR(root->right); | |
} | |
void top_view(node * root) | |
{ | |
if(root==NULL) | |
return; | |
top_viewL(root->left); | |
printf("%d ", root->data); | |
top_viewR(root->right); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment