0% found this document useful (0 votes)
6 views

Binary Tree Traversal Inorde Sit

Uploaded by

Atul Suradkar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Binary Tree Traversal Inorde Sit

Uploaded by

Atul Suradkar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>
#include <stdlib.h>

struct Node {
int data;
struct Node* left;
struct Node* right;
};

// Function to perform inorder traversal


void inorderTraversal(struct Node* root) {

// Empty Tree
if (root == NULL)
return;

// Recur on the left subtree


inorderTraversal(root->left);

// Visit the current node


printf("%d ", root->data);

// Recur on the right subtree


inorderTraversal(root->right);
}

// Function to create a new 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;
}

int main() {
struct Node* root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
printf("Inorder traversal: ");
inorderTraversal(root);
printf("\n");
return 0;
}

You might also like