dsa 8
dsa 8
#include <iostream.h>
#include<conio.h>
class Node {
public:
int data;
Node* left;
Node* right;
Node(int v)
this->data = v;
};
// Preorder Traversal
if (node == NULL)
return;
// Visit Node
printPreOrder(node->left);
printPreOrder(node->right);
// Driver code
void main()
// Function call
printPreOrder(root);
getch();
Output :
#include <iostream.h>
#include<conio.h>
class Node {
public:
int data;
Node* left;
Node* right;
Node(int v)
this->data = v;
};
// Inorder Traversal
if (node == NULL)
return;
printInorder(node->left);
// Visit node
printInorder(node->right);
// Driver code
void main()
// Function call
printInorder(root);
getch();
Output :
#include <iostream.h>
#include<conio.h>
class Node {
public:
int data;
Node* left;
Node* right;
Node(int v)
this->data = v;
}
};
// PostOrder Traversal
if (node == NULL)
return;
printPostOrder(node->left);
printPostOrder(node->right);
// Visit node
// Driver code
void main()
// Function call
printPostOrder(root);
getch();
Output: