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

Code 3-10-2020

The document contains C code to create a binary tree node structure and recursively traverse the tree in postorder. It defines a node structure with left, right pointers and data, creates a node by getting user input and recursively creating child nodes, and defines a postorder traversal function to print the nodes.

Uploaded by

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

Code 3-10-2020

The document contains C code to create a binary tree node structure and recursively traverse the tree in postorder. It defines a node structure with left, right pointers and data, creates a node by getting user input and recursively creating child nodes, and defines a postorder traversal function to print the nodes.

Uploaded by

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

#include<stdio.

h>
#include<stdlib.h>
#include<math.h>
struct node
{
struct node *left;
struct node *right;
char data;
};
struct node *create()
{
int choice;
struct node *nn;
nn=(struct node *)malloc(sizeof(struct node));
printf("Enter the data ");
scanf(" %c",&nn->data);
nn->left=NULL;
nn->right=NULL;
printf("Press 1 if %c has left node\nPress 0 otherwise",nn->data);
scanf("%d",&choice);
if(choice)
{
nn->left=create();
}
printf("Press 1 if %c has right node\nPress 0 otherwise",nn->data);
scanf("%d",&choice);
if(choice)
{
nn->right=create();
}
return nn;
}
void postorder(struct node *root)
{
if(root==NULL)
return;
else
{
postorder(root->left);
postorder(root->right);
printf("%c",root->data);
}
}
int main()
{
struct node *root;
root=create();
postorder(root);
return 0;
}

You might also like