"tree traversal" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "tree traversal" answered properly. Developers are finding an appropriate answer about tree traversal related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like tree traversal. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on tree traversal.
preorder traversal
#include <iostream>
using namespace std;
class node{
public:
int data;
node* left;
node* right;
node(int d){
data = d;
left = NULL;
right = NULL;
}
};
node* buildTree(){
int d;
cin>>d;
if(d==-1){
return NULL; //to attach a NULL pointer[in case of no child] enter -1
}
node * root = new node(d);
root->left = buildTree();
root->right = buildTree();
return root;
}
//REQUIRED FUNCTION: Inorder Traversal
void printIn(node*root){
if(root==NULL){
return;
}
//Otherwise Left Root Right
printIn(root->left);
cout<<root->data<<" ";
printIn(root->right);
}
int main(){
node* root = buildTree();
printIn(root);
return 0;
}
//SAMPLE INPUT TO RUN THE CODE ON ANY ONLINE IDE:
//8 10 1 -1 -1 6 9 -1 -1 7 -1 -1 3 -1 14 13 -1 -1 -1
All those coders who are working on the Whatever based application and are stuck on tree traversal can get a collection of related answers to their query. Programmers need to enter their query on tree traversal related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about tree traversal for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of tree traversal while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "tree traversal". Visit this developer's friendly online web community, CodeProZone, and get your queries like tree traversal resolved professionally and stay updated to the latest Whatever updates.