preorder traversal c++

C++
#include<iostream>
using namespace std;

struct node {
   int data;
   struct node *left;
   struct node *right;
};

void preorder(struct node *root) {
   if (root != NULL) {
      cout<<root->data<<" ";
      preorder(root->left);
      preorder(root->right);
   }
}
Source

Also in C++: