File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ /* Tree Node Structure */
2+
3+ struct Node {
4+ int data;
5+ Node* left;
6+ Node* right;
7+ };
8+
9+ /* Inorder Traversal of Binary tree */
10+
11+ void inorderTraversal(Node* root) {
12+ if (root == NULL)
13+ return;
14+ /* recurring on left child */
15+ inorderTraversal(root->left);
16+
17+ /* printing the data of node */
18+ cout << root->data << " ";
19+
20+ /* recurring on right child */
21+ inorderTraversal(root->right);
22+ }
23+
24+ /* Preorder Traversal of Binary tree */
25+
26+ void preorderTraversal(Node* root) {
27+ if (root == NULL)
28+ return;
29+ /* printing the data of node */
30+ cout << root->data << " ";
31+
32+ /* recurring on left child */
33+ preorderTraversal(root->left);
34+
35+ /* recurring on right child */
36+ preorderTraversal(root->right);
37+ }
38+
39+
40+ /* Postorder Traversal of Binary tree */
41+
42+ void postorderTraversal(Node* root) {
43+ if (root == NULL)
44+ return;
45+ /* recurring on left child */
46+ postorderTraversal(root->left);
47+
48+ /* recurring on right child */
49+ postorderTraversal(root->right);
50+
51+ /* printing the data of node */
52+ cout << root->data << " ";
53+ }
You can’t perform that action at this time.
0 commit comments