#include <iostream>
using namespace std;

class binary{
    public:
    int data;
    binary *left,*right;
    
    binary(int value){
        data = value;
        left = right = NULL;
    }
};

void pre_print(binary* root){
    if(root == NULL)
        return;
    else{
        cout<<root->data<<" ";
        pre_print(root->left);
        pre_print(root->right);
    }    
}

void in_print(binary* root){
    if(root == NULL)
        return;
    else{
        in_print(root->left);
        cout<<root->data<<" ";
        in_print(root->right);
    }    
}

void post_print(binary* root){
    if(root == NULL)
        return;
    else{
        post_print(root->left);
        post_print(root->right);
        cout<<root->data<<" ";
    }    
}

int main(){
    binary *root = new binary(1);
    binary *left = new binary(2);
    binary *right = new binary(3);
    binary *left_left = new binary(4);
    binary *left_right = new binary(5);
    binary *right_left = new binary(6);
    binary *right_right = new binary(7);
    
    //connections..
    root->left = left;
    root->right = right;
    left->left = left_left;
    left->right = left_right;
    right->left = right_left;
    right->right = right_right;
    
    cout<<"Preorder: ";
    pre_print(root);
    cout<<"\nInorder: ";
    in_print(root);
    cout<<"\nPostorder: ";
    post_print(root);
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: