-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathnonlinear_binary_tree.c
More file actions
37 lines (29 loc) · 925 Bytes
/
nonlinear_binary_tree.c
File metadata and controls
37 lines (29 loc) · 925 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
#include <stdio.h>
#include <stdlib.h>
struct TreeNode {
int data;
struct TreeNode* left;
struct TreeNode* right;
};
int main() {
struct TreeNode* root = (struct TreeNode*)malloc(sizeof(struct TreeNode));
struct TreeNode* leftChild = (struct TreeNode*)malloc(sizeof(struct TreeNode));
struct TreeNode* rightChild = (struct TreeNode*)malloc(sizeof(struct TreeNode));
root->data = 50;
root->left = leftChild;
root->right = rightChild;
leftChild->data = 30;
leftChild->left = NULL;
leftChild->right = NULL;
rightChild->data = 70;
rightChild->left = NULL;
rightChild->right = NULL;
printf("Binary Tree Structure:\n");
printf("Root: %d\n", root->data);
printf("Left Child: %d\n", root->left->data);
printf("Right Child: %d\n", root->right->data);
free(root);
free(leftChild);
free(rightChild);
return 0;
}