SlideShare a Scribd company logo
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
 
#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
ajoy21
 
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
 
Compiler Design Unit 3
Compiler Design Unit 3Compiler Design Unit 3
Compiler Design Unit 3
Jena Catherine Bel D
 
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
 
pointers
pointerspointers
pointers
Jeet Thummar
 
-- 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
 
Data Structures and Agorithm: DS 14 Binary Expression Tree.pptx
Data Structures and Agorithm: DS 14 Binary Expression Tree.pptxData Structures and Agorithm: DS 14 Binary Expression Tree.pptx
Data Structures and Agorithm: DS 14 Binary Expression Tree.pptx
RashidFaridChishti
 
pointers
pointerspointers
pointers
teach4uin
 
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
 
Unit 1 LINEAR DATA STRUCTURES
Unit 1  LINEAR DATA STRUCTURESUnit 1  LINEAR DATA STRUCTURES
Unit 1 LINEAR DATA STRUCTURES
Usha Mahalingam
 
Final ds record
Final ds recordFinal ds record
Final ds record
Ganisius Ganish
 
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
 
L 17 ct1120
L 17 ct1120L 17 ct1120
L 17 ct1120
Zia Ush Shamszaman
 
Assignment-6 (2).docx
Assignment-6 (2).docxAssignment-6 (2).docx
Assignment-6 (2).docx
kantrajnee88
 

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
 
Data Structures and Agorithm: DS 14 Binary Expression Tree.pptx
Data Structures and Agorithm: DS 14 Binary Expression Tree.pptxData Structures and Agorithm: DS 14 Binary Expression Tree.pptx
Data Structures and Agorithm: DS 14 Binary Expression Tree.pptx
 
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
 

More from thangarajarivukadal

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
thangarajarivukadal
 
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
thangarajarivukadal
 
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
thangarajarivukadal
 
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
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
 
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
thangarajarivukadal
 
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
thangarajarivukadal
 
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
thangarajarivukadal
 
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
thangarajarivukadal
 
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
thangarajarivukadal
 
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
thangarajarivukadal
 
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
thangarajarivukadal
 
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
thangarajarivukadal
 
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
thangarajarivukadal
 
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
thangarajarivukadal
 
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
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
 
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
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

Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 

Recently uploaded (20)

Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 

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);