Home > OS >  How do I declare the root as global and set it to null to indicate an empty tree in a structure in c
How do I declare the root as global and set it to null to indicate an empty tree in a structure in c

Time:05-13

As a beginner in c , I have encountered a problem trying to implement a structure for binary search tree. Shown below is part of my code but c kept reminding me that the "data member initializer is not allowed".

#include<iostream>
using namespace std;

struct BstNode{int key; BstNode*Left; BstNode*Right; BstNode*root = NULL;};

CodePudding user response:

You simply write

BstNode *root = nullptr;

outside of the struct.

  •  Tags:  
  • c
  • Related