Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created May 10, 2016 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/f7742a123f3524c1d0fbd98e71c8f516 to your computer and use it in GitHub Desktop.
Save jianminchen/f7742a123f3524c1d0fbd98e71c8f516 to your computer and use it in GitHub Desktop.
HackerRank - Tree - Tree Top view
/*
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