Tree representation in C

Below is an example to represent a Tree structure in C using struct –


struct nodetype{

int info;

struct nodetype * left;

struct nodetype * right;

struct nodetype * father;

}

typedef struct nodetype * NODEPTR;

NODEPTR maketree (int x){

NODEPTR getnode (void);

NODEPTR P;

P = getnode();

P -> info = x;

P -> left = NULL;

P -> right= NULL;

P -> father= NULL;

return (P);

}

NODEPTR getnode(void) {

return ( (NODEPTR) malloc (sizeof struct nodetype) )

}