Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class Node{
- public:
- int key;
- Node *left;
- Node *right;
- Node( int k)
- {
- key = k;
- left = right = NULL;
- }
- };
- class Tree{
- public:
- Node *root;
- void printInorder( Node *temp )
- {
- if( temp == NULL){
- return;
- }
- printInorder( temp -> left);
- cout<<temp->key;
- printInorder( temp -> right);
- }
- };
- int main()
- {
- Node *n1 = new Node(1);
- Node *n2 = new Node(2);
- Node *n3 = new Node(3);
- Node *n4 = new Node(4);
- Node *n5 = new Node(5);
- Tree *t = new Tree();
- t -> root = n1;
- t -> root -> left = n2;
- t -> root ->right = n3;
- t -> root -> left -> left = n4;
- t -> root -> left -> right = n5;
- t ->printInorder(n1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement