what means this declaration?

I've found from Internet this code about a binary tree:

===============================================
#include <iostream>
#include <cstdlib>
using namespace std;

class BinarySearchTree
{
private:
struct tree_node
{
tree_node* left;
tree_node* right;
int data;
};
tree_node* root;

public:
BinarySearchTree()
{
root = NULL;
}

bool isEmpty() const { return root==NULL; }
void print_inorder();
void inorder(tree_node*);
void print_preorder();
void preorder(tree_node*);
void print_postorder();
void postorder(tree_node*);
void insert(int);
void remove(int);
};
==================================================


but I don't understand the meaning of tree_node*.
tree_node is the structure's name which is a member of the class BinarySearchTree but what's about tree_node*? What means the asterisk after tree_node?
Thanks
tree_node* means it's a pointer to a tree_node object.
By the way instead of

1
2
3
4
5
6
7
8
private:
 struct tree_node
 {
 tree_node* left;
 tree_node* right;
 int data;
 };
 tree_node* root;


it could be written as


1
2
3
4
5
6
7
private:
 struct tree_node
 {
 tree_node* left;
 tree_node* right;
 int data;
 } *root;
Yes, it could, but the question is, is it more readable that way?
In my opinion yes it is.
That way is more C-ish.

Personal preference, but I prefer the OP's style more. About the only time I combine the object declaration with the struct declaration is if the struct is anonymous.
It depends in whether the structure is used only for defining pointer root, or it is used as public type name.
Topic archived. No new replies allowed.