For the level order of the binary tree:

1- start from the root, display it

2-put the left child and then right child in a queue

3-again consider the first element of the queue as root and repeat the procedure till the whole tree is traversed.

here is the C code :

`void levelorder(struct tnode *p)`

{

struct tnode *queue[100]={(struct tnode*) 0};

int size=0;

int qptr=0;

while(p)

{

printf("%d\t",p->data);

if(p->left)

{

queue[size++]=p->left;

}

if(p->right)

{

queue[size++]=p->right;

}

p=queue[qptr++];

}

}

Advertisements