SlideShare a Scribd company logo
Binary Trees in C
Write a C function that accepts a pointer to a binary tree and a pointer to a node of the tree and
returns the level of the node in the tree.
Solution
Answer:
sturct binarytreenode {
int data;
struct binarytreenode *left;
struct binarytreenode *right;
}
int find(struct binarytreenode *tree, struct binarytreenode *u, int height)
{
int leftheight,rightheight;
if(tree==NULL)
return(-1);
if(tree==u)
return(height);
leftheight=find(tree->left,u,height+1);
if (leftheight != -1)
return(leftheight);
else
return(find(tree->right,u,height+1));
}
main()
{
struct binarytreenode *root, *u
height(root, u, 0);
}
Binary Trees in C Write a C function that accepts a pointer to a binar.docx

More Related Content

More from curtisp2

Calculate the cell potential (Ecell for the following lead concentrati.docx
Calculate the cell potential (Ecell for the following lead concentrati.docxCalculate the cell potential (Ecell for the following lead concentrati.docx
Calculate the cell potential (Ecell for the following lead concentrati.docx
curtisp2
 
Calculate -OH-- concentration of solutions with the following pH value.docx
Calculate -OH-- concentration of solutions with the following pH value.docxCalculate -OH-- concentration of solutions with the following pH value.docx
Calculate -OH-- concentration of solutions with the following pH value.docx
curtisp2
 
Cafeteria plan has following advantages- 1-Employees more likely to ap.docx
Cafeteria plan has following advantages- 1-Employees more likely to ap.docxCafeteria plan has following advantages- 1-Employees more likely to ap.docx
Cafeteria plan has following advantages- 1-Employees more likely to ap.docx
curtisp2
 
C++ a) What is a null pointer- b) Give an example of a function that r.docx
C++ a) What is a null pointer- b) Give an example of a function that r.docxC++ a) What is a null pointer- b) Give an example of a function that r.docx
C++ a) What is a null pointer- b) Give an example of a function that r.docx
curtisp2
 
By treating a student as aSolutionInvitation of appliction for admissi.docx
By treating a student as aSolutionInvitation of appliction for admissi.docxBy treating a student as aSolutionInvitation of appliction for admissi.docx
By treating a student as aSolutionInvitation of appliction for admissi.docx
curtisp2
 
By how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docx
By how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docxBy how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docx
By how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docx
curtisp2
 
Build a trie of the following terms using- a- A pointer representation.docx
Build a trie of the following terms using- a- A pointer representation.docxBuild a trie of the following terms using- a- A pointer representation.docx
Build a trie of the following terms using- a- A pointer representation.docx
curtisp2
 

More from curtisp2 (7)

Calculate the cell potential (Ecell for the following lead concentrati.docx
Calculate the cell potential (Ecell for the following lead concentrati.docxCalculate the cell potential (Ecell for the following lead concentrati.docx
Calculate the cell potential (Ecell for the following lead concentrati.docx
 
Calculate -OH-- concentration of solutions with the following pH value.docx
Calculate -OH-- concentration of solutions with the following pH value.docxCalculate -OH-- concentration of solutions with the following pH value.docx
Calculate -OH-- concentration of solutions with the following pH value.docx
 
Cafeteria plan has following advantages- 1-Employees more likely to ap.docx
Cafeteria plan has following advantages- 1-Employees more likely to ap.docxCafeteria plan has following advantages- 1-Employees more likely to ap.docx
Cafeteria plan has following advantages- 1-Employees more likely to ap.docx
 
C++ a) What is a null pointer- b) Give an example of a function that r.docx
C++ a) What is a null pointer- b) Give an example of a function that r.docxC++ a) What is a null pointer- b) Give an example of a function that r.docx
C++ a) What is a null pointer- b) Give an example of a function that r.docx
 
By treating a student as aSolutionInvitation of appliction for admissi.docx
By treating a student as aSolutionInvitation of appliction for admissi.docxBy treating a student as aSolutionInvitation of appliction for admissi.docx
By treating a student as aSolutionInvitation of appliction for admissi.docx
 
By how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docx
By how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docxBy how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docx
By how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docx
 
Build a trie of the following terms using- a- A pointer representation.docx
Build a trie of the following terms using- a- A pointer representation.docxBuild a trie of the following terms using- a- A pointer representation.docx
Build a trie of the following terms using- a- A pointer representation.docx
 

Recently uploaded

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
 
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)
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
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
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
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
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
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
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 

Recently uploaded (20)

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
 
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...
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
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
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
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
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 

Binary Trees in C Write a C function that accepts a pointer to a binar.docx

  • 1. Binary Trees in C Write a C function that accepts a pointer to a binary tree and a pointer to a node of the tree and returns the level of the node in the tree. Solution Answer: sturct binarytreenode { int data; struct binarytreenode *left; struct binarytreenode *right; } int find(struct binarytreenode *tree, struct binarytreenode *u, int height) { int leftheight,rightheight; if(tree==NULL) return(-1); if(tree==u) return(height); leftheight=find(tree->left,u,height+1); if (leftheight != -1) return(leftheight); else return(find(tree->right,u,height+1)); } main() { struct binarytreenode *root, *u height(root, u, 0); }