#include <iostream> using namespace std; class Tree { struct Node { string data; // Changed 'type' to 'string' to match the data being inserted Node* left; Node* right; Node(string d) : data(d), left(nullptr), right(nullptr) {} }; public: Node* root = nullptr; Tree() { Node* f = new Node("F"); Node* g = new Node("G"); Node* h = new Node("H"); f->left = g; f->right = h; root = f; // Corrected 'Root' to 'root' } void preorder(Node* ptr) { if (ptr != nullptr) { cout << ptr->data << " "; ...
Comments
Post a Comment