SlideShare a Scribd company logo
1 of 2
Download to read offline
Please write a non-recursive procedure to print all nodes for a binary tree in a level order
sequence.
Solution
#include
#include
struct node
{
int data;
struct node* left, *right;
};
void printGivenLevel(struct node* root, int level);
int height(struct node* node);
struct node* newNode(int data);
void printLevelOrder(struct node* root)
{
int h = height(root);
int i;
for (i=1; i<=h; i++)
printGivenLevel(root, i);
}
void printGivenLevel(struct node* root, int level)
{
if (root == NULL)
return;
if (level == 1)
printf("%d ", root->data);
else if (level > 1)
{
printGivenLevel(root->left, level-1);
printGivenLevel(root->right, level-1);
}
}
int height(struct node* node)
{
if (node==NULL)
return 0;
else
{
int lheight = height(node->left);
int rheight = height(node->right);
if (lheight > rheight)
return(lheight+1);
else return(rheight+1);
}
}
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("Level Order traversal of binary tree is  ");
printLevelOrder(root);
return 0;
}

More Related Content

Similar to Please write a non-recursive procedure to print all nodes for a bina.pdf

hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++mustkeem khan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diplomamustkeem khan
 
Here is the code given in the instructionsclass AVL {.pdf
Here is the code given in the instructionsclass AVL {.pdfHere is the code given in the instructionsclass AVL {.pdf
Here is the code given in the instructionsclass AVL {.pdfmanjan6
 
fix the error - class Node{ int data- Node next-.pdf
fix the error -   class Node{           int data-           Node next-.pdffix the error -   class Node{           int data-           Node next-.pdf
fix the error - class Node{ int data- Node next-.pdfAKVIGFOEU
 
You can list anything, it doesnt matter. I just want to see code f.pdf
You can list anything, it doesnt matter. I just want to see code f.pdfYou can list anything, it doesnt matter. I just want to see code f.pdf
You can list anything, it doesnt matter. I just want to see code f.pdffashionbigchennai
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfmail931892
 
Write code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxWrite code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxnoreendchesterton753
 
C programming. Answer question only in C code Ninth Deletion with B.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdfC programming. Answer question only in C code Ninth Deletion with B.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdfinfo309708
 
the header file code for double link list#include iostream#.pdf
the header file code for double link list#include iostream#.pdfthe header file code for double link list#include iostream#.pdf
the header file code for double link list#include iostream#.pdffashination
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresLakshmi Sarvani Videla
 
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.pdfSANDEEPARIHANT
 
1. Add a breadth-first (level-order) traversal function to the binar.pdf
1. Add a breadth-first (level-order) traversal function to the binar.pdf1. Add a breadth-first (level-order) traversal function to the binar.pdf
1. Add a breadth-first (level-order) traversal function to the binar.pdfarjuncp10
 
Write a function in C++ to generate an N-node random binary search t.pdf
Write a function in C++ to generate an N-node random binary search t.pdfWrite a function in C++ to generate an N-node random binary search t.pdf
Write a function in C++ to generate an N-node random binary search t.pdfinfo824691
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxtristans3
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 

Similar to Please write a non-recursive procedure to print all nodes for a bina.pdf (20)

hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
week-4x
week-4xweek-4x
week-4x
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
Here is the code given in the instructionsclass AVL {.pdf
Here is the code given in the instructionsclass AVL {.pdfHere is the code given in the instructionsclass AVL {.pdf
Here is the code given in the instructionsclass AVL {.pdf
 
fix the error - class Node{ int data- Node next-.pdf
fix the error -   class Node{           int data-           Node next-.pdffix the error -   class Node{           int data-           Node next-.pdf
fix the error - class Node{ int data- Node next-.pdf
 
You can list anything, it doesnt matter. I just want to see code f.pdf
You can list anything, it doesnt matter. I just want to see code f.pdfYou can list anything, it doesnt matter. I just want to see code f.pdf
You can list anything, it doesnt matter. I just want to see code f.pdf
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
 
Write code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxWrite code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docx
 
C programming. Answer question only in C code Ninth Deletion with B.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdfC programming. Answer question only in C code Ninth Deletion with B.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdf
 
the header file code for double link list#include iostream#.pdf
the header file code for double link list#include iostream#.pdfthe header file code for double link list#include iostream#.pdf
the header file code for double link list#include iostream#.pdf
 
Programs.doc
Programs.docPrograms.doc
Programs.doc
 
AI-Programs.pdf
AI-Programs.pdfAI-Programs.pdf
AI-Programs.pdf
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
7 functions
7  functions7  functions
7 functions
 
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
 
1. Add a breadth-first (level-order) traversal function to the binar.pdf
1. Add a breadth-first (level-order) traversal function to the binar.pdf1. Add a breadth-first (level-order) traversal function to the binar.pdf
1. Add a breadth-first (level-order) traversal function to the binar.pdf
 
Write a function in C++ to generate an N-node random binary search t.pdf
Write a function in C++ to generate an N-node random binary search t.pdfWrite a function in C++ to generate an N-node random binary search t.pdf
Write a function in C++ to generate an N-node random binary search t.pdf
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docx
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 

More from arcotstarsports

You are presented with a patient, named Gerry, who has Down syndrome .pdf
You are presented with a patient, named Gerry, who has Down syndrome .pdfYou are presented with a patient, named Gerry, who has Down syndrome .pdf
You are presented with a patient, named Gerry, who has Down syndrome .pdfarcotstarsports
 
Write a template function to fill in a STL list with a given array..pdf
Write a template function to fill in a STL list with a given array..pdfWrite a template function to fill in a STL list with a given array..pdf
Write a template function to fill in a STL list with a given array..pdfarcotstarsports
 
write a method to generate AVL tree of height h wth fewest nodes and.pdf
write a method to generate AVL tree of height h wth fewest nodes and.pdfwrite a method to generate AVL tree of height h wth fewest nodes and.pdf
write a method to generate AVL tree of height h wth fewest nodes and.pdfarcotstarsports
 
Which of the following is NOT correctWhich of the following is NO.pdf
Which of the following is NOT correctWhich of the following is NO.pdfWhich of the following is NOT correctWhich of the following is NO.pdf
Which of the following is NOT correctWhich of the following is NO.pdfarcotstarsports
 
What is Mills response to the problem posed by some peoples desi.pdf
What is Mills response to the problem posed by some peoples desi.pdfWhat is Mills response to the problem posed by some peoples desi.pdf
What is Mills response to the problem posed by some peoples desi.pdfarcotstarsports
 
What is a bivariate distributionSolutionBivariate distributio.pdf
What is a bivariate distributionSolutionBivariate distributio.pdfWhat is a bivariate distributionSolutionBivariate distributio.pdf
What is a bivariate distributionSolutionBivariate distributio.pdfarcotstarsports
 
What are some of the tools you can use to tune or correct a Linux fi.pdf
What are some of the tools you can use to tune or correct a Linux fi.pdfWhat are some of the tools you can use to tune or correct a Linux fi.pdf
What are some of the tools you can use to tune or correct a Linux fi.pdfarcotstarsports
 
TrueFalse Insulin spikes in the postabsorptive state.Solution.pdf
TrueFalse Insulin spikes in the postabsorptive state.Solution.pdfTrueFalse Insulin spikes in the postabsorptive state.Solution.pdf
TrueFalse Insulin spikes in the postabsorptive state.Solution.pdfarcotstarsports
 
The principal role of ATP In the cell is A) serving as structural s.pdf
The principal role of ATP In the cell is  A) serving as structural s.pdfThe principal role of ATP In the cell is  A) serving as structural s.pdf
The principal role of ATP In the cell is A) serving as structural s.pdfarcotstarsports
 
The neutral theory of evolution proposed that most genetic mutations .pdf
The neutral theory of evolution proposed that most genetic mutations .pdfThe neutral theory of evolution proposed that most genetic mutations .pdf
The neutral theory of evolution proposed that most genetic mutations .pdfarcotstarsports
 
The oldest living organisms on Earth are plants. Some bristlecone pi.pdf
The oldest living organisms on Earth are plants. Some bristlecone pi.pdfThe oldest living organisms on Earth are plants. Some bristlecone pi.pdf
The oldest living organisms on Earth are plants. Some bristlecone pi.pdfarcotstarsports
 
Suppose there is a person whose total lung capacity (TLC) is 4.90 L, .pdf
Suppose there is a person whose total lung capacity (TLC) is 4.90 L, .pdfSuppose there is a person whose total lung capacity (TLC) is 4.90 L, .pdf
Suppose there is a person whose total lung capacity (TLC) is 4.90 L, .pdfarcotstarsports
 
Research the IPv4 ns the IPv6 protocols, then prepare a report that .pdf
Research the IPv4 ns the IPv6 protocols, then prepare a report that .pdfResearch the IPv4 ns the IPv6 protocols, then prepare a report that .pdf
Research the IPv4 ns the IPv6 protocols, then prepare a report that .pdfarcotstarsports
 
Species I Species II Species III Species IV Ancestral sequence IV Sit.pdf
Species I Species II Species III Species IV Ancestral sequence IV Sit.pdfSpecies I Species II Species III Species IV Ancestral sequence IV Sit.pdf
Species I Species II Species III Species IV Ancestral sequence IV Sit.pdfarcotstarsports
 
Solve the differential equation y+y=sin(x). Im thinking I ne.pdf
Solve the differential equation y+y=sin(x). Im thinking I ne.pdfSolve the differential equation y+y=sin(x). Im thinking I ne.pdf
Solve the differential equation y+y=sin(x). Im thinking I ne.pdfarcotstarsports
 
Please do C, D, and E For the given f Z right arrow Z, decide wheth.pdf
Please do C, D, and E For the given f Z right arrow Z, decide wheth.pdfPlease do C, D, and E For the given f Z right arrow Z, decide wheth.pdf
Please do C, D, and E For the given f Z right arrow Z, decide wheth.pdfarcotstarsports
 
need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfarcotstarsports
 
Microbiology question Which of the following is the most unique a.pdf
Microbiology question Which of the following is the most unique a.pdfMicrobiology question Which of the following is the most unique a.pdf
Microbiology question Which of the following is the most unique a.pdfarcotstarsports
 
Is Event B dependent or independent of Event A A green ball is draw.pdf
Is Event B dependent or independent of Event A A green ball is draw.pdfIs Event B dependent or independent of Event A A green ball is draw.pdf
Is Event B dependent or independent of Event A A green ball is draw.pdfarcotstarsports
 
In this view, the front of the heart has been reflected upwards. Ide.pdf
In this view, the front of the heart has been reflected upwards. Ide.pdfIn this view, the front of the heart has been reflected upwards. Ide.pdf
In this view, the front of the heart has been reflected upwards. Ide.pdfarcotstarsports
 

More from arcotstarsports (20)

You are presented with a patient, named Gerry, who has Down syndrome .pdf
You are presented with a patient, named Gerry, who has Down syndrome .pdfYou are presented with a patient, named Gerry, who has Down syndrome .pdf
You are presented with a patient, named Gerry, who has Down syndrome .pdf
 
Write a template function to fill in a STL list with a given array..pdf
Write a template function to fill in a STL list with a given array..pdfWrite a template function to fill in a STL list with a given array..pdf
Write a template function to fill in a STL list with a given array..pdf
 
write a method to generate AVL tree of height h wth fewest nodes and.pdf
write a method to generate AVL tree of height h wth fewest nodes and.pdfwrite a method to generate AVL tree of height h wth fewest nodes and.pdf
write a method to generate AVL tree of height h wth fewest nodes and.pdf
 
Which of the following is NOT correctWhich of the following is NO.pdf
Which of the following is NOT correctWhich of the following is NO.pdfWhich of the following is NOT correctWhich of the following is NO.pdf
Which of the following is NOT correctWhich of the following is NO.pdf
 
What is Mills response to the problem posed by some peoples desi.pdf
What is Mills response to the problem posed by some peoples desi.pdfWhat is Mills response to the problem posed by some peoples desi.pdf
What is Mills response to the problem posed by some peoples desi.pdf
 
What is a bivariate distributionSolutionBivariate distributio.pdf
What is a bivariate distributionSolutionBivariate distributio.pdfWhat is a bivariate distributionSolutionBivariate distributio.pdf
What is a bivariate distributionSolutionBivariate distributio.pdf
 
What are some of the tools you can use to tune or correct a Linux fi.pdf
What are some of the tools you can use to tune or correct a Linux fi.pdfWhat are some of the tools you can use to tune or correct a Linux fi.pdf
What are some of the tools you can use to tune or correct a Linux fi.pdf
 
TrueFalse Insulin spikes in the postabsorptive state.Solution.pdf
TrueFalse Insulin spikes in the postabsorptive state.Solution.pdfTrueFalse Insulin spikes in the postabsorptive state.Solution.pdf
TrueFalse Insulin spikes in the postabsorptive state.Solution.pdf
 
The principal role of ATP In the cell is A) serving as structural s.pdf
The principal role of ATP In the cell is  A) serving as structural s.pdfThe principal role of ATP In the cell is  A) serving as structural s.pdf
The principal role of ATP In the cell is A) serving as structural s.pdf
 
The neutral theory of evolution proposed that most genetic mutations .pdf
The neutral theory of evolution proposed that most genetic mutations .pdfThe neutral theory of evolution proposed that most genetic mutations .pdf
The neutral theory of evolution proposed that most genetic mutations .pdf
 
The oldest living organisms on Earth are plants. Some bristlecone pi.pdf
The oldest living organisms on Earth are plants. Some bristlecone pi.pdfThe oldest living organisms on Earth are plants. Some bristlecone pi.pdf
The oldest living organisms on Earth are plants. Some bristlecone pi.pdf
 
Suppose there is a person whose total lung capacity (TLC) is 4.90 L, .pdf
Suppose there is a person whose total lung capacity (TLC) is 4.90 L, .pdfSuppose there is a person whose total lung capacity (TLC) is 4.90 L, .pdf
Suppose there is a person whose total lung capacity (TLC) is 4.90 L, .pdf
 
Research the IPv4 ns the IPv6 protocols, then prepare a report that .pdf
Research the IPv4 ns the IPv6 protocols, then prepare a report that .pdfResearch the IPv4 ns the IPv6 protocols, then prepare a report that .pdf
Research the IPv4 ns the IPv6 protocols, then prepare a report that .pdf
 
Species I Species II Species III Species IV Ancestral sequence IV Sit.pdf
Species I Species II Species III Species IV Ancestral sequence IV Sit.pdfSpecies I Species II Species III Species IV Ancestral sequence IV Sit.pdf
Species I Species II Species III Species IV Ancestral sequence IV Sit.pdf
 
Solve the differential equation y+y=sin(x). Im thinking I ne.pdf
Solve the differential equation y+y=sin(x). Im thinking I ne.pdfSolve the differential equation y+y=sin(x). Im thinking I ne.pdf
Solve the differential equation y+y=sin(x). Im thinking I ne.pdf
 
Please do C, D, and E For the given f Z right arrow Z, decide wheth.pdf
Please do C, D, and E For the given f Z right arrow Z, decide wheth.pdfPlease do C, D, and E For the given f Z right arrow Z, decide wheth.pdf
Please do C, D, and E For the given f Z right arrow Z, decide wheth.pdf
 
need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdf
 
Microbiology question Which of the following is the most unique a.pdf
Microbiology question Which of the following is the most unique a.pdfMicrobiology question Which of the following is the most unique a.pdf
Microbiology question Which of the following is the most unique a.pdf
 
Is Event B dependent or independent of Event A A green ball is draw.pdf
Is Event B dependent or independent of Event A A green ball is draw.pdfIs Event B dependent or independent of Event A A green ball is draw.pdf
Is Event B dependent or independent of Event A A green ball is draw.pdf
 
In this view, the front of the heart has been reflected upwards. Ide.pdf
In this view, the front of the heart has been reflected upwards. Ide.pdfIn this view, the front of the heart has been reflected upwards. Ide.pdf
In this view, the front of the heart has been reflected upwards. Ide.pdf
 

Recently uploaded

How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
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...Nguyen Thanh Tu Collection
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
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 RoomSean M. Fox
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
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
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
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).pptxneillewis46
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
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 Partnershipsexpandedwebsite
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 

Recently uploaded (20)

How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
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...
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
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
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
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...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
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
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
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
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 

Please write a non-recursive procedure to print all nodes for a bina.pdf

  • 1. Please write a non-recursive procedure to print all nodes for a binary tree in a level order sequence. Solution #include #include struct node { int data; struct node* left, *right; }; void printGivenLevel(struct node* root, int level); int height(struct node* node); struct node* newNode(int data); void printLevelOrder(struct node* root) { int h = height(root); int i; for (i=1; i<=h; i++) printGivenLevel(root, i); } void printGivenLevel(struct node* root, int level) { if (root == NULL) return; if (level == 1) printf("%d ", root->data); else if (level > 1) { printGivenLevel(root->left, level-1); printGivenLevel(root->right, level-1); } } int height(struct node* node)
  • 2. { if (node==NULL) return 0; else { int lheight = height(node->left); int rheight = height(node->right); if (lheight > rheight) return(lheight+1); else return(rheight+1); } } 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("Level Order traversal of binary tree is "); printLevelOrder(root); return 0; }