-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatingTree.c
More file actions
44 lines (40 loc) · 992 Bytes
/
creatingTree.c
File metadata and controls
44 lines (40 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include<stdlib.h>
//declaration of the tree element right, left and data type
struct node
{
int data;
struct node *left;
struct node *right;
}*Node;
//Creating root node
struct node *create()
{
int x;
//struct node *newnode;
struct node *newnode=(struct node*)malloc(sizeof(struct node));
printf ("Enter the data for the nodes (-1 for no data)");
scanf("%d",&x);
newnode->data=x;
if(x==-1)
{
printf ("Not entered any data\n");
return NULL;
}
printf("Enter the left child of the rooted data %d\t",newnode->data);
newnode->left=create();
printf("Enter the right child of the rooted data %d\t",newnode->data);
newnode->right=create();
return newnode;
}
int main ()
{
//struct node *t,*root;
struct node *root=create();
struct node *t=root;
//traverse(t);
printf ("Root child : %d\n",t->data);
printf ("Inorder traversal\n");
Inorder(t);
return 0;
}