Created
December 7, 2018 16:56
-
-
Save saifsmailbox98/0a9dd732e5bbb28de4086de896c100d6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <stdio.h> | |
struct node | |
{ | |
int data; | |
struct node *left; | |
struct node *right; | |
}; | |
typedef struct node * NODE; | |
struct node* newNode(int data) | |
{ | |
struct node* node = (struct node*)malloc(sizeof(struct node)); | |
node->data = data; | |
node->left = NULL; | |
node->right = NULL; | |
return(node); | |
} | |
void display(NODE root, int level){ | |
if(root == NULL) return; | |
display(root->right, level + 1); | |
for(int i = 0; i < level; i++) printf(" "); | |
printf("%d\n", root->data); | |
display(root->left, level + 1); | |
} | |
int main() | |
{ | |
struct node *root = newNode(1); | |
root->left = newNode(2); | |
root->right = newNode(3); | |
root->left->left = newNode(4); | |
display(root, 0); | |
getchar(); | |
return 0; | |
} | |
/* | |
OUTPUT: | |
3 | |
1 | |
2 | |
4 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment