My issue
run time error prob
lem in code how to solve
My code
#include <stdio.h>
#include <stdlib.h>
typedef struct Solution {
void (*preOrderTraversal)(Node* root);
} Solution;
// Function to perform pre-order traversal
void preOrderTraversal(Node* root) {
if (root == NULL) {
return; // Base case: if the node is NULL, do nothing
}
printf("%d ", root->val); // Visit the current node (print its value)
// Traverse the left subtree
preOrderTraversal(root->left);
// Traverse the right subtree
preOrderTraversal(root->right);
}
// Function to create a new Solution object and return it
Solution* createSolution() {
Solution* sol = (Solution*)malloc(sizeof(Solution)); // Allocate memory for Solution
sol->preOrderTraversal = preOrderTraversal; // Assign the function pointer
return sol;
}
Learning course: BCS301: Data structures
Problem Link: https://www.codechef.com/learn/course/abesit-dsa/ABESITDS29/problems/BTPREORDER