-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinorderTree.c
44 lines (37 loc) · 994 Bytes
/
inorderTree.c
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>
// Define the node structure
struct node {
int data;
struct node* left;
struct node* right;
};
// Function to create a new node
struct node* createNode(int data) {
struct node* n = (struct node*)malloc(sizeof(struct node));
n->data = data;
n->left = NULL;
n->right = NULL;
return n;
}
// Function for postorder traversal
void inorderTraversal(struct node* node) {
if (node == NULL) {
return;
}
inorderTraversal(node->left);
printf("%d ", node->data);
inorderTraversal(node->right);
}
int main() {
struct node* root = createNode(10);
root->left = createNode(20);
root->right = createNode(30);
root->left->left = createNode(40);
root->left->right = createNode(50);
root->right->left = createNode(60);
root->right->right = createNode(70);
printf("Inorder traversal is: ");
inorderTraversal(root);
return 0;
}