SlideShare a Scribd company logo
1 of 4
Download to read offline
1. Create the binary tree with 9 nodes (Figure 1) by using pointer-based representation.
struct TreeNode
{
int info;
TreeNode * left;
TreeNode * right;
}
2.
Implement pre-order, in-order, and post-order traversals, and print the results of the tree
The pre-order transversal looks like this: 2 7 2 6 5 11 5 9 4
The in-order transversal looks like this: 2 7 5 6 11 2 5 4 9
The post-order transversal looks like this: 2 5 11 6 7 4 9 5 2
Solution
Here is the code for you:
#include
#include
#include
typedef struct node
{
int info;
struct node *left;
struct node *right;
} node;
void insert(node **,int);
void preorder(node *);
void postorder(node *);
void inorder(node *);
int main()
{
node *root;
int ch,ele;
root=NULL;
while(1)
{
printf("TREE OPERATIONS ");
printf("1.INSERT ");
printf("2.INORDER ");
printf("3.PREORDER ");
printf("4.POSTORDER ");
printf("5.EXIT ");
printf("Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("Enter the element you want to insert: ");
scanf("%d",&ele);
insert(&root,ele);
break;
case 2: inorder(root);
break;
case 3: preorder(root);
break;
case 4: postorder(root);
break;
case 5: exit(0);
default: printf("Invalid Choice. Please enter a valid choice. ");
}
}
}
void insert(node **root, int ele)
{
node *temp,*x,*y;
x=y=*root;
temp= (node *)malloc(sizeof(node));
temp->info=ele;
temp->left = temp->right = NULL;
while(x!=NULL)
{
y=x;
if(ele < x->info)
x = x->left;
else
x = x->right;
}
if(y == NULL)
*root=temp;
else if(ele < y->info)
y->left = temp;
else
y->right = temp;
}
void inorder(node *root)
{
if(root != NULL)
{
inorder(root->left);
printf("%d ",root->info);
inorder(root->right);
}
}
void preorder(node *root)
{
if(root != NULL)
{
printf("%d ",root->info);
inorder(root->left);
inorder(root->right);
}
}
void postorder(node *root)
{
if(root != NULL)
{
inorder(root->left);
inorder(root->right);
printf("%d ",root->info);
}
}

More Related Content

Similar to 1. Create the binary tree with 9 nodes (Figure 1) by using pointer-b.pdf

Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdf
SANDEEPARIHANT
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
josies1
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdf
wasemanivytreenrco51
 
I have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdfI have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdf
fasttrackscardecors
 
How to build a Linked List that can insert any type of data. For exa.pdf
How to build a Linked List that can insert any type of data. For exa.pdfHow to build a Linked List that can insert any type of data. For exa.pdf
How to build a Linked List that can insert any type of data. For exa.pdf
arpittradersjdr
 
Please write the C++ code that would display the exact same output a.pdf
Please write the C++ code that would display the exact same output a.pdfPlease write the C++ code that would display the exact same output a.pdf
Please write the C++ code that would display the exact same output a.pdf
amarndsons
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
shanki7
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
Adamq0DJonese
 
Write a program to decipher messages encoded using a prefix code, gi.pdf
Write a program to decipher messages encoded using a prefix code, gi.pdfWrite a program to decipher messages encoded using a prefix code, gi.pdf
Write a program to decipher messages encoded using a prefix code, gi.pdf
footworld1
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
fastechsrv
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
 
Write a C++ function to delete the given value from the binary search.docx
Write a C++ function to delete the given value from the binary search.docxWrite a C++ function to delete the given value from the binary search.docx
Write a C++ function to delete the given value from the binary search.docx
noreendchesterton753
 

Similar to 1. Create the binary tree with 9 nodes (Figure 1) by using pointer-b.pdf (20)

Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdf
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdf
 
#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx
 
I have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdfI have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdf
 
Compiler Design Unit 3
Compiler Design Unit 3Compiler Design Unit 3
Compiler Design Unit 3
 
How to build a Linked List that can insert any type of data. For exa.pdf
How to build a Linked List that can insert any type of data. For exa.pdfHow to build a Linked List that can insert any type of data. For exa.pdf
How to build a Linked List that can insert any type of data. For exa.pdf
 
Please write the C++ code that would display the exact same output a.pdf
Please write the C++ code that would display the exact same output a.pdfPlease write the C++ code that would display the exact same output a.pdf
Please write the C++ code that would display the exact same output a.pdf
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
 
pointers
pointerspointers
pointers
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
 
pointers
pointerspointers
pointers
 
Write a program to decipher messages encoded using a prefix code, gi.pdf
Write a program to decipher messages encoded using a prefix code, gi.pdfWrite a program to decipher messages encoded using a prefix code, gi.pdf
Write a program to decipher messages encoded using a prefix code, gi.pdf
 
Unit 1 LINEAR DATA STRUCTURES
Unit 1  LINEAR DATA STRUCTURESUnit 1  LINEAR DATA STRUCTURES
Unit 1 LINEAR DATA STRUCTURES
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
L 17 ct1120
L 17 ct1120L 17 ct1120
L 17 ct1120
 
Assignment-6 (2).docx
Assignment-6 (2).docxAssignment-6 (2).docx
Assignment-6 (2).docx
 
Write a C++ function to delete the given value from the binary search.docx
Write a C++ function to delete the given value from the binary search.docxWrite a C++ function to delete the given value from the binary search.docx
Write a C++ function to delete the given value from the binary search.docx
 

More from thangarajarivukadal

You will construct a manual for your company that defines the Risk M.pdf
You will construct a manual for your company that defines the Risk M.pdfYou will construct a manual for your company that defines the Risk M.pdf
You will construct a manual for your company that defines the Risk M.pdf
thangarajarivukadal
 
Which of the following statements about DNA and RNA are true, and wh.pdf
Which of the following statements about DNA and RNA are true, and wh.pdfWhich of the following statements about DNA and RNA are true, and wh.pdf
Which of the following statements about DNA and RNA are true, and wh.pdf
thangarajarivukadal
 
Q i.Why is it, in general the fracture toughness of ductile material.pdf
Q i.Why is it, in general the fracture toughness of ductile material.pdfQ i.Why is it, in general the fracture toughness of ductile material.pdf
Q i.Why is it, in general the fracture toughness of ductile material.pdf
thangarajarivukadal
 
Junior collects baseball cards. He owns one Felix Hernandez card tha.pdf
Junior collects baseball cards. He owns one Felix Hernandez card tha.pdfJunior collects baseball cards. He owns one Felix Hernandez card tha.pdf
Junior collects baseball cards. He owns one Felix Hernandez card tha.pdf
thangarajarivukadal
 

More from thangarajarivukadal (20)

Which of the following is not a high-speed Internet assess service.pdf
Which of the following is not a high-speed Internet assess service.pdfWhich of the following is not a high-speed Internet assess service.pdf
Which of the following is not a high-speed Internet assess service.pdf
 
Write a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfWrite a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdf
 
Which of the following describes silver A material that has a low r.pdf
Which of the following describes silver  A material that has a low r.pdfWhich of the following describes silver  A material that has a low r.pdf
Which of the following describes silver A material that has a low r.pdf
 
why dont most other types of bacteria produce ulcers ( like helico.pdf
why dont most other types of bacteria produce ulcers ( like helico.pdfwhy dont most other types of bacteria produce ulcers ( like helico.pdf
why dont most other types of bacteria produce ulcers ( like helico.pdf
 
You will construct a manual for your company that defines the Risk M.pdf
You will construct a manual for your company that defines the Risk M.pdfYou will construct a manual for your company that defines the Risk M.pdf
You will construct a manual for your company that defines the Risk M.pdf
 
Which of the following statements about DNA and RNA are true, and wh.pdf
Which of the following statements about DNA and RNA are true, and wh.pdfWhich of the following statements about DNA and RNA are true, and wh.pdf
Which of the following statements about DNA and RNA are true, and wh.pdf
 
You observe a cell switch from performing cellular respiration to per.pdf
You observe a cell switch from performing cellular respiration to per.pdfYou observe a cell switch from performing cellular respiration to per.pdf
You observe a cell switch from performing cellular respiration to per.pdf
 
You are speaking to a group of high school students in a technology .pdf
You are speaking to a group of high school students in a technology .pdfYou are speaking to a group of high school students in a technology .pdf
You are speaking to a group of high school students in a technology .pdf
 
Who might use financial statements List at least 3 examples of like.pdf
Who might use financial statements List at least 3 examples of like.pdfWho might use financial statements List at least 3 examples of like.pdf
Who might use financial statements List at least 3 examples of like.pdf
 
What could be the rational for IRC exempting income from bonds issue.pdf
What could be the rational for IRC exempting income from bonds issue.pdfWhat could be the rational for IRC exempting income from bonds issue.pdf
What could be the rational for IRC exempting income from bonds issue.pdf
 
Tropical forests are extremely important ecosystems on the planet. Ho.pdf
Tropical forests are extremely important ecosystems on the planet. Ho.pdfTropical forests are extremely important ecosystems on the planet. Ho.pdf
Tropical forests are extremely important ecosystems on the planet. Ho.pdf
 
We learn of the the black dwarf, the final stage in a death of a low.pdf
We learn of the the black dwarf, the final stage in a death of a low.pdfWe learn of the the black dwarf, the final stage in a death of a low.pdf
We learn of the the black dwarf, the final stage in a death of a low.pdf
 
What are the main responsibilities of the Network Layer What are th.pdf
What are the main responsibilities of the Network Layer What are th.pdfWhat are the main responsibilities of the Network Layer What are th.pdf
What are the main responsibilities of the Network Layer What are th.pdf
 
These organs in spiders produce with In this kind of circulato.pdf
These organs in spiders produce with  In this kind of circulato.pdfThese organs in spiders produce with  In this kind of circulato.pdf
These organs in spiders produce with In this kind of circulato.pdf
 
Ensign Danielle Anderson returned from a Qualified Hazardous Duty Ar.pdf
Ensign Danielle Anderson returned from a Qualified Hazardous Duty Ar.pdfEnsign Danielle Anderson returned from a Qualified Hazardous Duty Ar.pdf
Ensign Danielle Anderson returned from a Qualified Hazardous Duty Ar.pdf
 
Oxidation and reduction states are relatively easy to determine for m.pdf
Oxidation and reduction states are relatively easy to determine for m.pdfOxidation and reduction states are relatively easy to determine for m.pdf
Oxidation and reduction states are relatively easy to determine for m.pdf
 
Question 9 (1 point) What is data visualization O Making a mental no.pdf
Question 9 (1 point) What is data visualization O Making a mental no.pdfQuestion 9 (1 point) What is data visualization O Making a mental no.pdf
Question 9 (1 point) What is data visualization O Making a mental no.pdf
 
Q i.Why is it, in general the fracture toughness of ductile material.pdf
Q i.Why is it, in general the fracture toughness of ductile material.pdfQ i.Why is it, in general the fracture toughness of ductile material.pdf
Q i.Why is it, in general the fracture toughness of ductile material.pdf
 
Problem 1. Think about an individual that you are investigating from .pdf
Problem 1. Think about an individual that you are investigating from .pdfProblem 1. Think about an individual that you are investigating from .pdf
Problem 1. Think about an individual that you are investigating from .pdf
 
Junior collects baseball cards. He owns one Felix Hernandez card tha.pdf
Junior collects baseball cards. He owns one Felix Hernandez card tha.pdfJunior collects baseball cards. He owns one Felix Hernandez card tha.pdf
Junior collects baseball cards. He owns one Felix Hernandez card tha.pdf
 

Recently uploaded

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 

Recently uploaded (20)

Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 

1. Create the binary tree with 9 nodes (Figure 1) by using pointer-b.pdf

  • 1. 1. Create the binary tree with 9 nodes (Figure 1) by using pointer-based representation. struct TreeNode { int info; TreeNode * left; TreeNode * right; } 2. Implement pre-order, in-order, and post-order traversals, and print the results of the tree The pre-order transversal looks like this: 2 7 2 6 5 11 5 9 4 The in-order transversal looks like this: 2 7 5 6 11 2 5 4 9 The post-order transversal looks like this: 2 5 11 6 7 4 9 5 2 Solution Here is the code for you: #include #include #include typedef struct node { int info; struct node *left; struct node *right; } node; void insert(node **,int); void preorder(node *); void postorder(node *); void inorder(node *); int main() { node *root; int ch,ele; root=NULL; while(1)
  • 2. { printf("TREE OPERATIONS "); printf("1.INSERT "); printf("2.INORDER "); printf("3.PREORDER "); printf("4.POSTORDER "); printf("5.EXIT "); printf("Enter your choice: "); scanf("%d",&ch); switch(ch) { case 1: printf("Enter the element you want to insert: "); scanf("%d",&ele); insert(&root,ele); break; case 2: inorder(root); break; case 3: preorder(root); break; case 4: postorder(root); break; case 5: exit(0); default: printf("Invalid Choice. Please enter a valid choice. "); } } } void insert(node **root, int ele) { node *temp,*x,*y; x=y=*root; temp= (node *)malloc(sizeof(node)); temp->info=ele; temp->left = temp->right = NULL; while(x!=NULL) { y=x;
  • 3. if(ele < x->info) x = x->left; else x = x->right; } if(y == NULL) *root=temp; else if(ele < y->info) y->left = temp; else y->right = temp; } void inorder(node *root) { if(root != NULL) { inorder(root->left); printf("%d ",root->info); inorder(root->right); } } void preorder(node *root) { if(root != NULL) { printf("%d ",root->info); inorder(root->left); inorder(root->right); } } void postorder(node *root) { if(root != NULL) { inorder(root->left); inorder(root->right);