# level of a binary tree

• 01-09-2009
BEN10
level of a binary tree
hello all,
here is a question

Quote:

write a c-function that accepts a pointer to a binary tree & a pointer to a node of the tree and returns the level of the node in the tree.
i've made a function that accepts a pointer to a node and finds the level of the node in the tree.
Code:

```int level(struct node *p) { int level=0; struct node *r; for(r=p;r->father!=NULL;r=p->father) level++; return(level); }```
my problem is that how can i make a function that should accept another pointer to the tree and returns the level.and also i'm not able to understand what does a pointer to a tree means.is it an array of nodes.
thanks
• 01-09-2009
hk_mp5kpdw
From your description, your function should take two arguments (pointers) instead of just the one you've provided. Is this a binary search tree or just a generalized binary tree (ordered/unordered)?

Quote:

Originally Posted by BEN10
and also i'm not able to understand what does a pointer to a tree means.is it an array of nodes.

As long as struct node contains pointers to itself, then the pointers you are dealing with are "tree" pointers. The nodes and the other nodes they point to represent the tree object. It can be physically represented using an array of contiguous memory or as a group of distinct/non-adjacent memory locations.
• 01-09-2009
BEN10
Quote:

Is this a binary search tree or just a generalized binary tree (ordered/unordered)?
this is a unordered generalized binary tree.
still i'm not able to understand what is a pointer to a tree.
i'm declaring the nodes as
Code:

```struct node { int info; struct node *left; struct node *right; struct node *father; };```
• 01-09-2009
iMalc
A pointer to a node within a tree, and a pointer to a tree, are the same thing.
• 01-09-2009
tabstop
More specifically, a pointer to a tree is the same as a pointer to the root of that tree.